From a3e56141d9c19bdbaa5e1317ed3fc488c9b0b48e Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Tue, 17 May 2022 15:12:12 +0200 Subject: [PATCH] carddav: 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 CardDAV collection listable with clients that do require it, e.g. cadaver. [1]: https://datatracker.ietf.org/doc/html/rfc2518#section-13.4 --- carddav/carddav.go | 9 +++++---- carddav/server.go | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/carddav/carddav.go b/carddav/carddav.go index 68d3244..6a52400 100644 --- a/carddav/carddav.go +++ b/carddav/carddav.go @@ -100,10 +100,11 @@ type AddressBookMultiGet struct { } type AddressObject struct { - Path string - ModTime time.Time - ETag string - Card vcard.Card + Path string + ModTime time.Time + ContentLength int64 + ETag string + Card vcard.Card } //SyncQuery is the query struct represents a sync-collection request diff --git a/carddav/server.go b/carddav/server.go index ea474d6..93bf5f4 100644 --- a/carddav/server.go +++ b/carddav/server.go @@ -441,6 +441,11 @@ func (b *backend) propfindAddressObject(ctx context.Context, propfind *internal. }, } + if ao.ContentLength > 0 { + props[internal.GetContentLengthName] = func(*internal.RawXMLValue) (interface{}, error) { + return &internal.GetContentLength{Length: ao.ContentLength}, nil + } + } if !ao.ModTime.IsZero() { props[internal.GetLastModifiedName] = func(*internal.RawXMLValue) (interface{}, error) { return &internal.GetLastModified{LastModified: internal.Time(ao.ModTime)}, nil