Skip to content

Commit

Permalink
Upload-Length in HEAD responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Nov 2, 2024
1 parent afba1b0 commit 06cc82a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/handler/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func TestHead(t *testing.T) {
ResHeader: addIETFUploadCompleteHeader(map[string]string{
"Upload-Draft-Interop-Version": interopVersion,
"Upload-Offset": "5",
"Upload-Length": "10",
}, false, interopVersion),
}).Run(handler, t)
})
Expand Down Expand Up @@ -209,6 +210,7 @@ func TestHead(t *testing.T) {
ResHeader: addIETFUploadCompleteHeader(map[string]string{
"Upload-Draft-Interop-Version": interopVersion,
"Upload-Offset": "10",
"Upload-Length": "10",
}, true, interopVersion),
}).Run(handler, t)
})
Expand Down Expand Up @@ -241,6 +243,7 @@ func TestHead(t *testing.T) {
ResHeader: addIETFUploadCompleteHeader(map[string]string{
"Upload-Draft-Interop-Version": interopVersion,
"Upload-Offset": "5",
"Upload-Length": "",
}, false, interopVersion),
}).Run(handler, t)
})
Expand Down
6 changes: 6 additions & 0 deletions pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
resp.Header["Upload-Defer-Length"] = UploadLengthDeferred
} else {
resp.Header["Upload-Length"] = strconv.FormatInt(info.Size, 10)
// TODO: Shouldn't this rather be offset? Basically, whatever GET would return.
// But this then also depends on the storage backend if that's even supported.
resp.Header["Content-Length"] = strconv.FormatInt(info.Size, 10)
}

Expand All @@ -689,6 +691,10 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
setIETFDraftUploadComplete(r, resp, isUploadCompleteNow)
resp.Header["Upload-Draft-Interop-Version"] = string(getIETFDraftInteropVersion(r))

if !info.SizeIsDeferred {
resp.Header["Upload-Length"] = strconv.FormatInt(info.Size, 10)
}

// Draft -01 and -02 require a 204 No Content response. Version -03 allows 200 OK as well,
// but we stick to 204 to not make the logic less complex.
resp.StatusCode = http.StatusNoContent
Expand Down

0 comments on commit 06cc82a

Please sign in to comment.