mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
carddav: add Content-Length support to client
This commit is contained in:
parent
1e99b70a62
commit
5d845721d8
@ -246,6 +246,11 @@ func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
|
||||
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)
|
||||
card, err := vcard.NewDecoder(r).Decode()
|
||||
if err != nil {
|
||||
@ -255,6 +260,7 @@ func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
|
||||
addrs = append(addrs, AddressObject{
|
||||
Path: path,
|
||||
ModTime: time.Time(getLastMod.LastModified),
|
||||
ContentLength: getContentLength.Length,
|
||||
ETag: string(getETag.ETag),
|
||||
Card: card,
|
||||
})
|
||||
@ -345,6 +351,13 @@ func populateAddressObject(ao *AddressObject, resp *http.Response) error {
|
||||
}
|
||||
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 != "" {
|
||||
t, err := http.ParseTime(lastModified)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user