carddav: PUT support
This commit is contained in:
15
webdav.go
15
webdav.go
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user