carddav: add Content-Length support to client

This commit is contained in:
Conrad Hoffmann 2022-05-24 11:02:34 +02:00 committed by Simon Ser
parent 1e99b70a62
commit 5d845721d8

View File

@ -246,6 +246,11 @@ func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
return nil, err return nil, err
} }
var getContentLength internal.GetContentLength
if err := resp.DecodeProp(&getContentLength); err != nil && !internal.IsNotFound(err) {
return nil, err
}
r := bytes.NewReader(addrData.Data) r := bytes.NewReader(addrData.Data)
card, err := vcard.NewDecoder(r).Decode() card, err := vcard.NewDecoder(r).Decode()
if err != nil { if err != nil {
@ -253,10 +258,11 @@ func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
} }
addrs = append(addrs, AddressObject{ addrs = append(addrs, AddressObject{
Path: path, Path: path,
ModTime: time.Time(getLastMod.LastModified), ModTime: time.Time(getLastMod.LastModified),
ETag: string(getETag.ETag), ContentLength: getContentLength.Length,
Card: card, ETag: string(getETag.ETag),
Card: card,
}) })
} }
@ -345,6 +351,13 @@ func populateAddressObject(ao *AddressObject, resp *http.Response) error {
} }
ao.ETag = etag ao.ETag = etag
} }
if contentLength := resp.Header.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 := resp.Header.Get("Last-Modified"); lastModified != "" {
t, err := http.ParseTime(lastModified) t, err := http.ParseTime(lastModified)
if err != nil { if err != nil {