From 491af8e42c912628d65c6a29eaf1f38630ebaa7c Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Tue, 17 May 2022 14:43:17 +0200 Subject: [PATCH] caldav: add support for getcontentlength property Allow the backend to provide a value for the `getcontentlength` property as described in [RFC 2518 section 13.4][1]. The implementation treats is as optional, allthough it is a required property per RFC. Most clients do perfectly fine without it, though. Properly setting this in the backend makes the CalDAV collection listable with clients that do require it, e.g. cadaver. [1]: https://datatracker.ietf.org/doc/html/rfc2518#section-13.4 --- caldav/caldav.go | 9 +++++---- caldav/server.go | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/caldav/caldav.go b/caldav/caldav.go index 9d5ca11..014e257 100644 --- a/caldav/caldav.go +++ b/caldav/caldav.go @@ -117,8 +117,9 @@ type CalendarMultiGet struct { } type CalendarObject struct { - Path string - ModTime time.Time - ETag string - Data *ical.Calendar + Path string + ModTime time.Time + ContentLength int64 + ETag string + Data *ical.Calendar } diff --git a/caldav/server.go b/caldav/server.go index f713174..b7273f5 100644 --- a/caldav/server.go +++ b/caldav/server.go @@ -465,6 +465,11 @@ func (b *backend) propfindCalendarObject(ctx context.Context, propfind *internal }, } + if co.ContentLength > 0 { + props[internal.GetContentLengthName] = func(*internal.RawXMLValue) (interface{}, error) { + return &internal.GetContentLength{Length: co.ContentLength}, nil + } + } if !co.ModTime.IsZero() { props[internal.GetLastModifiedName] = func(*internal.RawXMLValue) (interface{}, error) { return &internal.GetLastModified{LastModified: internal.Time(co.ModTime)}, nil