mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
carddav: fix Client.PutAddressObject failing with Radicale
This is workaround for a Radicale issue. References: https://github.com/Kozea/Radicale/issues/1016
This commit is contained in:
parent
a81a7014c6
commit
236dc07837
@ -3,7 +3,6 @@ package carddav
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -323,16 +322,24 @@ func (c *Client) MultiGetAddressBook(path string, multiGet *AddressBookMultiGet)
|
||||
func (c *Client) PutAddressObject(path string, card vcard.Card) (*AddressObject, error) {
|
||||
// TODO: add support for If-None-Match and If-Match
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
// TODO: some servers want a Content-Length header, so we can't stream the
|
||||
// request body here. See the Radicale issue:
|
||||
// https://github.com/Kozea/Radicale/issues/1016
|
||||
|
||||
go func() {
|
||||
err := vcard.NewEncoder(pw).Encode(card)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
//pr, pw := io.Pipe()
|
||||
//go func() {
|
||||
// err := vcard.NewEncoder(pw).Encode(card)
|
||||
// pw.CloseWithError(err)
|
||||
//}()
|
||||
|
||||
req, err := c.ic.NewRequest(http.MethodPut, path, pr)
|
||||
var buf bytes.Buffer
|
||||
if err := vcard.NewEncoder(&buf).Encode(card); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := c.ic.NewRequest(http.MethodPut, path, &buf)
|
||||
if err != nil {
|
||||
pr.Close()
|
||||
//pr.Close()
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", vcard.MIMEType)
|
||||
|
Loading…
Reference in New Issue
Block a user