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:
Simon Ser 2020-02-12 21:10:52 +01:00
parent a81a7014c6
commit 236dc07837
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -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)