Refactor Upload-Length handling to use early returns
This commit is contained in:
parent
7fd0139355
commit
7f11b92fab
|
@ -461,26 +461,26 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Header.Get("Upload-Length") != "" {
|
if r.Header.Get("Upload-Length") != "" {
|
||||||
if handler.composer.UsesLengthDeferrer {
|
if !handler.composer.UsesLengthDeferrer {
|
||||||
if info.SizeIsDeferred {
|
handler.sendError(w, r, ErrNotImplemented)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !info.SizeIsDeferred {
|
||||||
|
handler.sendError(w, r, ErrInvalidUploadLength)
|
||||||
|
return
|
||||||
|
}
|
||||||
uploadLength, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
|
uploadLength, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
|
||||||
if err != nil || uploadLength < 0 || uploadLength < info.Offset || uploadLength > handler.config.MaxSize {
|
if err != nil || uploadLength < 0 || uploadLength < info.Offset || uploadLength > handler.config.MaxSize {
|
||||||
handler.sendError(w, r, ErrInvalidUploadLength)
|
handler.sendError(w, r, ErrInvalidUploadLength)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err := handler.composer.LengthDeferrer.DeclareLength(id, uploadLength); err != nil {
|
||||||
info.Size = uploadLength
|
|
||||||
info.SizeIsDeferred = false
|
|
||||||
if err := handler.composer.LengthDeferrer.DeclareLength(id, info.Size); err != nil {
|
|
||||||
handler.sendError(w, r, err)
|
handler.sendError(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
handler.sendError(w, r, ErrInvalidUploadLength)
|
info.Size = uploadLength
|
||||||
}
|
info.SizeIsDeferred = false
|
||||||
} else {
|
|
||||||
handler.sendError(w, r, ErrNotImplemented)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := handler.writeChunk(id, info, w, r); err != nil {
|
if err := handler.writeChunk(id, info, w, r); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue