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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"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) {
|
func (c *Client) PutAddressObject(path string, card vcard.Card) (*AddressObject, error) {
|
||||||
// TODO: add support for If-None-Match and If-Match
|
// 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() {
|
//pr, pw := io.Pipe()
|
||||||
err := vcard.NewEncoder(pw).Encode(card)
|
//go func() {
|
||||||
pw.CloseWithError(err)
|
// 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 {
|
if err != nil {
|
||||||
pr.Close()
|
//pr.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", vcard.MIMEType)
|
req.Header.Set("Content-Type", vcard.MIMEType)
|
||||||
|
Loading…
Reference in New Issue
Block a user