Return appropriate errors if upload-length is misused in PATCH requests
This commit is contained in:
parent
22fdd3935b
commit
a366b00e3e
|
@ -459,18 +459,26 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if handler.composer.UsesLengthDeferrer && info.SizeIsDeferred && r.Header.Get("Upload-Length") != "" {
|
||||
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)
|
||||
return
|
||||
}
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
info.Size = uploadLength
|
||||
info.SizeIsDeferred = false
|
||||
if err := handler.composer.LengthDeferrer.DeclareLength(id, info.Size); err != nil {
|
||||
handler.sendError(w, r, err)
|
||||
return
|
||||
info.Size = uploadLength
|
||||
info.SizeIsDeferred = false
|
||||
if err := handler.composer.LengthDeferrer.DeclareLength(id, info.Size); err != nil {
|
||||
handler.sendError(w, r, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
handler.sendError(w, r, ErrInvalidUploadLength)
|
||||
}
|
||||
} else {
|
||||
handler.sendError(w, r, ErrNotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue