Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>
"fmt"
"html"
"html/template"
"fmt"
"html"
"html/template"
// sends an HTTP header indicating success, updateOnSuccess first
// calls the provided update func. If the update func fails, a 500
// response is sent, and the status code and body sent by the handler
// sends an HTTP header indicating success, updateOnSuccess first
// calls the provided update func. If the update func fails, a 500
// response is sent, and the status code and body sent by the handler
-// are ignored (all response writes return errors).
+// are ignored (all response writes return the update error).
type updateOnSuccess struct {
httpserver.ResponseWriter
update func() error
sentHeader bool
type updateOnSuccess struct {
httpserver.ResponseWriter
update func() error
sentHeader bool
-var errUpdateFailed = errors.New("update failed")
-
func (uos *updateOnSuccess) Write(p []byte) (int, error) {
func (uos *updateOnSuccess) Write(p []byte) (int, error) {
- if uos.dropBody {
- return 0, errUpdateFailed
+ if uos.err != nil {
+ return 0, uos.err
}
if !uos.sentHeader {
uos.WriteHeader(http.StatusOK)
}
if !uos.sentHeader {
uos.WriteHeader(http.StatusOK)
func (uos *updateOnSuccess) WriteHeader(code int) {
if !uos.sentHeader {
func (uos *updateOnSuccess) WriteHeader(code int) {
if !uos.sentHeader {
if code >= 200 && code < 400 {
if code >= 200 && code < 400 {
- if err := uos.update(); err != nil {
- http.Error(uos.ResponseWriter, err.Error(), http.StatusInternalServerError)
- uos.dropBody = true
+ if uos.err = uos.update(); uos.err != nil {
+ http.Error(uos.ResponseWriter, uos.err.Error(), http.StatusInternalServerError)
}
uos.ResponseWriter.WriteHeader(code)
}
var (
}
uos.ResponseWriter.WriteHeader(code)
}
var (
+ writeMethod = map[string]bool{
+ "DELETE": true,
+ "MKCOL": true,
+ "MOVE": true,
+ "PUT": true,
+ "RMCOL": true,
+ }
webdavMethod = map[string]bool{
"DELETE": true,
"MKCOL": true,
webdavMethod = map[string]bool{
"DELETE": true,
"MKCOL": true,
return
}
if webdavMethod[r.Method] {
return
}
if webdavMethod[r.Method] {
- writing := !arvadosclient.PDHMatch(targetID)
+ writing := !arvadosclient.PDHMatch(targetID) && writeMethod[r.Method]
if writing {
// Save the collection only if/when all
// webdav->filesystem operations succeed --
if writing {
// Save the collection only if/when all
// webdav->filesystem operations succeed --