Integrate DeclareLength into handler's PatchFile

This commit is contained in:
Adam Jensen 2018-05-13 09:52:27 -04:00
parent c6d5ad08c0
commit 7bd1cd6f9d
1 changed files with 5 additions and 1 deletions

View File

@ -456,7 +456,7 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
return
}
if info.SizeIsDeferred && r.Header.Get("Upload-Length") != "" {
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 {
handler.sendError(w, r, ErrInvalidOffset)
@ -465,6 +465,10 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
info.Size = uploadLength
info.SizeIsDeferred = false
if err := handler.composer.LengthDeferrer.DeclareLength(id, info.Size); err != nil {
handler.sendError(w, r, err)
return
}
}
if err := handler.writeChunk(id, info, w, r); err != nil {