Skip to content

Commit

Permalink
Upload-Limit in OPTIONS responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Nov 2, 2024
1 parent 06cc82a commit 7e370e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pkg/handler/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,26 @@ func TestOptions(t *testing.T) {
Code: http.StatusPreconditionFailed,
}).Run(handler, t)
})

SubTest(t, "ExperimentalProtocol", func(t *testing.T, store *MockFullDataStore, _ *StoreComposer) {
composer := NewStoreComposer()
composer.UseCore(store)

handler, _ := NewHandler(Config{
StoreComposer: composer,
EnableExperimentalProtocol: true,
MaxSize: 400,
})

(&httpTest{
Method: "OPTIONS",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "6",
},
ResHeader: map[string]string{
"Upload-Limit": "min-size=0,max-size=400",
},
Code: http.StatusOK,
}).Run(handler, t)
})
}
10 changes: 9 additions & 1 deletion pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,16 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
// Set appropriated headers in case of OPTIONS method allowing protocol
// discovery and end with an 204 No Content
if r.Method == "OPTIONS" {
ietfDraftLimits := "min-size=0"

if handler.config.MaxSize > 0 {
header.Set("Tus-Max-Size", strconv.FormatInt(handler.config.MaxSize, 10))
maxSizeStr := strconv.FormatInt(handler.config.MaxSize, 10)
header.Set("Tus-Max-Size", maxSizeStr)
ietfDraftLimits += ",max-size=" + maxSizeStr
}

if handler.usesIETFDraft(r) {
header.Set("Upload-Limit", ietfDraftLimits)
}

header.Set("Tus-Version", "1.0.0")
Expand Down

0 comments on commit 7e370e1

Please sign in to comment.