From 0e58dbb00392fa03ed2958d5ab3fdf31d664b75b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 18 Dec 2023 18:18:56 +0100 Subject: [PATCH] caldav, carddav: take header when populating object References: https://github.com/emersion/go-webdav/pull/134 --- caldav/client.go | 14 +++++++------- carddav/client.go | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/caldav/client.go b/caldav/client.go index cf68fca..24a28c0 100644 --- a/caldav/client.go +++ b/caldav/client.go @@ -268,29 +268,29 @@ func (c *Client) MultiGetCalendar(path string, multiGet *CalendarMultiGet) ([]Ca return decodeCalendarObjectList(ms) } -func populateCalendarObject(co *CalendarObject, resp *http.Response) error { - if loc := resp.Header.Get("Location"); loc != "" { +func populateCalendarObject(co *CalendarObject, h http.Header) error { + if loc := h.Get("Location"); loc != "" { u, err := url.Parse(loc) if err != nil { return err } co.Path = u.Path } - if etag := resp.Header.Get("ETag"); etag != "" { + if etag := h.Get("ETag"); etag != "" { etag, err := strconv.Unquote(etag) if err != nil { return err } co.ETag = etag } - if contentLength := resp.Header.Get("Content-Length"); contentLength != "" { + if contentLength := h.Get("Content-Length"); contentLength != "" { n, err := strconv.ParseInt(contentLength, 10, 64) if err != nil { return err } co.ContentLength = n } - if lastModified := resp.Header.Get("Last-Modified"); lastModified != "" { + if lastModified := h.Get("Last-Modified"); lastModified != "" { t, err := http.ParseTime(lastModified) if err != nil { return err @@ -331,7 +331,7 @@ func (c *Client) GetCalendarObject(path string) (*CalendarObject, error) { Path: resp.Request.URL.Path, Data: cal, } - if err := populateCalendarObject(co, resp); err != nil { + if err := populateCalendarObject(co, resp.Header); err != nil { return nil, err } return co, nil @@ -362,7 +362,7 @@ func (c *Client) PutCalendarObject(path string, cal *ical.Calendar) (*CalendarOb resp.Body.Close() co := &CalendarObject{Path: path} - if err := populateCalendarObject(co, resp); err != nil { + if err := populateCalendarObject(co, resp.Header); err != nil { return nil, err } return co, nil diff --git a/carddav/client.go b/carddav/client.go index af22331..0f35180 100644 --- a/carddav/client.go +++ b/carddav/client.go @@ -338,29 +338,29 @@ func (c *Client) MultiGetAddressBook(path string, multiGet *AddressBookMultiGet) return decodeAddressList(ms) } -func populateAddressObject(ao *AddressObject, resp *http.Response) error { - if loc := resp.Header.Get("Location"); loc != "" { +func populateAddressObject(ao *AddressObject, h http.Header) error { + if loc := h.Get("Location"); loc != "" { u, err := url.Parse(loc) if err != nil { return err } ao.Path = u.Path } - if etag := resp.Header.Get("ETag"); etag != "" { + if etag := h.Get("ETag"); etag != "" { etag, err := strconv.Unquote(etag) if err != nil { return err } ao.ETag = etag } - if contentLength := resp.Header.Get("Content-Length"); contentLength != "" { + if contentLength := h.Get("Content-Length"); contentLength != "" { n, err := strconv.ParseInt(contentLength, 10, 64) if err != nil { return err } ao.ContentLength = n } - if lastModified := resp.Header.Get("Last-Modified"); lastModified != "" { + if lastModified := h.Get("Last-Modified"); lastModified != "" { t, err := http.ParseTime(lastModified) if err != nil { return err @@ -401,7 +401,7 @@ func (c *Client) GetAddressObject(path string) (*AddressObject, error) { Path: resp.Request.URL.Path, Card: card, } - if err := populateAddressObject(ao, resp); err != nil { + if err := populateAddressObject(ao, resp.Header); err != nil { return nil, err } return ao, nil @@ -439,7 +439,7 @@ func (c *Client) PutAddressObject(path string, card vcard.Card) (*AddressObject, resp.Body.Close() ao := &AddressObject{Path: path} - if err := populateAddressObject(ao, resp); err != nil { + if err := populateAddressObject(ao, resp.Header); err != nil { return nil, err } return ao, nil