From 236dc078374ee8d1432ac56ca2f5bc0a48761e69 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 12 Feb 2020 21:10:52 +0100 Subject: [PATCH] carddav: fix Client.PutAddressObject failing with Radicale This is workaround for a Radicale issue. References: https://github.com/Kozea/Radicale/issues/1016 --- carddav/client.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/carddav/client.go b/carddav/client.go index 0e332f1..18b8798 100644 --- a/carddav/client.go +++ b/carddav/client.go @@ -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)