carddav: allow created address book objects to have a different path

Closes: https://github.com/emersion/go-webdav/issues/32
This commit is contained in:
Simon Ser
2020-01-30 15:20:10 +01:00
parent 2e5aa7653b
commit dd1527b97e
3 changed files with 21 additions and 13 deletions

View File

@@ -79,7 +79,7 @@ type Backend interface {
HeadGet(w http.ResponseWriter, r *http.Request) error
Propfind(r *http.Request, pf *Propfind, depth Depth) (*Multistatus, error)
Proppatch(r *http.Request, pu *Propertyupdate) (*Response, error)
Put(r *http.Request) error
Put(r *http.Request) (*Href, error)
Delete(r *http.Request) error
Mkcol(r *http.Request) error
Copy(r *http.Request, dest *Href, recursive, overwrite bool) (created bool, err error)
@@ -101,11 +101,14 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case http.MethodGet, http.MethodHead:
err = h.Backend.HeadGet(w, r)
case http.MethodPut:
err = h.Backend.Put(r)
var href *Href
href, err = h.Backend.Put(r)
if err == nil {
// TODO: Last-Modified, ETag, Content-Type if the request has
// been copied verbatim
// TODO: Location if the server has mutated the href
if href != nil {
w.Header().Set("Location", (*url.URL)(href).String())
}
w.WriteHeader(http.StatusCreated)
}
case http.MethodDelete: