mirror of
https://github.com/1f349/go-webdav.git
synced 2025-01-03 05:56:39 +00:00
caldav: add Content-Length support to client
Follow-up for https://github.com/emersion/go-webdav/pull/83.
This commit is contained in:
parent
38a35d3545
commit
9ed4abce57
@ -191,6 +191,11 @@ func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var getContentLength internal.GetContentLength
|
||||
if err := resp.DecodeProp(&getContentLength); err != nil && !internal.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := bytes.NewReader(calData.Data)
|
||||
data, err := ical.NewDecoder(r).Decode()
|
||||
if err != nil {
|
||||
@ -198,10 +203,11 @@ func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error
|
||||
}
|
||||
|
||||
addrs = append(addrs, CalendarObject{
|
||||
Path: path,
|
||||
ModTime: time.Time(getLastMod.LastModified),
|
||||
ETag: string(getETag.ETag),
|
||||
Data: data,
|
||||
Path: path,
|
||||
ModTime: time.Time(getLastMod.LastModified),
|
||||
ContentLength: getContentLength.Length,
|
||||
ETag: string(getETag.ETag),
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
@ -277,6 +283,13 @@ func populateCalendarObject(co *CalendarObject, resp *http.Response) error {
|
||||
}
|
||||
co.ETag = etag
|
||||
}
|
||||
if contentLength := resp.Header.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 != "" {
|
||||
t, err := http.ParseTime(lastModified)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user