Return appropriate errors if upload-length is misused in PATCH requests
@@ -459,7 +459,9 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
return
}
- if handler.composer.UsesLengthDeferrer && info.SizeIsDeferred && r.Header.Get("Upload-Length") != "" {
+ if r.Header.Get("Upload-Length") != "" {
+ if handler.composer.UsesLengthDeferrer {
+ if info.SizeIsDeferred {
uploadLength, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
if err != nil || uploadLength < 0 || uploadLength < info.Offset || uploadLength > handler.config.MaxSize {
handler.sendError(w, r, ErrInvalidUploadLength)
@@ -472,6 +474,12 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
handler.sendError(w, r, err)
return
}
+ } else {
+ handler.sendError(w, r, ErrInvalidUploadLength)
+ }
+ } else {
+ handler.sendError(w, r, ErrNotImplemented)
+ }
}
if err := handler.writeChunk(id, info, w, r); err != nil {
