carddav: PUT support

This commit is contained in:
emersion
2017-09-13 19:02:12 +02:00
parent 64f8396654
commit 2a7d999100
3 changed files with 118 additions and 36 deletions

View File

@@ -282,24 +282,31 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
if err != nil {
return http.StatusNotFound, err
}
_, copyErr := io.Copy(f, r.Body)
fi, statErr := f.Stat()
closeErr := f.Close()
fi, statErr := f.Stat()
// TODO(rost): Returning 405 Method Not Allowed might not be appropriate.
if copyErr != nil {
return http.StatusMethodNotAllowed, copyErr
}
if statErr != nil {
return http.StatusMethodNotAllowed, statErr
}
if closeErr != nil {
return http.StatusMethodNotAllowed, closeErr
}
if statErr != nil {
return http.StatusMethodNotAllowed, statErr
}
if path.Base(reqPath) != fi.Name() {
w.Header().Set("Location", path.Join(path.Dir(reqPath), fi.Name()))
}
etag, err := findETag(ctx, h.FileSystem, h.LockSystem, reqPath, fi)
if err != nil {
return http.StatusInternalServerError, err
}
w.Header().Set("ETag", etag)
return http.StatusCreated, nil
}