Skip to content

Commit

Permalink
handler: Support RUFH draft -03
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Mar 18, 2024
1 parent 9801b91 commit 361b2b4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/handler/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestHead(t *testing.T) {
})

SubTest(t, "ExperimentalProtocol", func(t *testing.T, _ *MockFullDataStore, _ *StoreComposer) {
for _, interopVersion := range []string{"3", "4"} {
for _, interopVersion := range []string{"3", "4", "5"} {
SubTest(t, "InteropVersion"+interopVersion, func(t *testing.T, _ *MockFullDataStore, _ *StoreComposer) {
SubTest(t, "IncompleteUpload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func TestPatch(t *testing.T) {
})

SubTest(t, "ExperimentalProtocol", func(t *testing.T, _ *MockFullDataStore, _ *StoreComposer) {
for _, interopVersion := range []string{"3", "4"} {
for _, interopVersion := range []string{"3", "4", "5"} {
SubTest(t, "InteropVersion"+interopVersion, func(t *testing.T, _ *MockFullDataStore, _ *StoreComposer) {
SubTest(t, "CompleteUploadWithKnownSize", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func TestPost(t *testing.T) {
})

SubTest(t, "ExperimentalProtocol", func(t *testing.T, _ *MockFullDataStore, _ *StoreComposer) {
for _, interopVersion := range []string{"3", "4"} {
for _, interopVersion := range []string{"3", "4", "5"} {
SubTest(t, "InteropVersion"+interopVersion, func(t *testing.T, _ *MockFullDataStore, _ *StoreComposer) {
SubTest(t, "CompleteUpload", func(t *testing.T, store *MockFullDataStore, _ *StoreComposer) {
ctrl := gomock.NewController(t)
Expand Down
10 changes: 6 additions & 4 deletions pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type draftVersion string
const (
interopVersion3 draftVersion = "3" // From draft version -01
interopVersion4 draftVersion = "4" // From draft version -02
interopVersion5 draftVersion = "5" // From draft version -03
)

var (
Expand Down Expand Up @@ -678,7 +679,8 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
setIETFDraftUploadComplete(r, resp, isUploadCompleteNow)
resp.Header["Upload-Draft-Interop-Version"] = string(getIETFDraftInteropVersion(r))

// Draft requires a 204 No Content response
// 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 Expand Up @@ -1364,7 +1366,7 @@ func (handler UnroutedHandler) usesIETFDraft(r *http.Request) bool {
func getIETFDraftInteropVersion(r *http.Request) draftVersion {
version := draftVersion(r.Header.Get("Upload-Draft-Interop-Version"))
switch version {
case interopVersion3, interopVersion4:
case interopVersion3, interopVersion4, interopVersion5:
return version
default:
return ""
Expand All @@ -1376,7 +1378,7 @@ func getIETFDraftInteropVersion(r *http.Request) draftVersion {
func isIETFDraftUploadComplete(r *http.Request) bool {
currentUploadDraftInteropVersion := getIETFDraftInteropVersion(r)
switch currentUploadDraftInteropVersion {
case interopVersion4:
case interopVersion4, interopVersion5:
return r.Header.Get("Upload-Complete") == "?1"
case interopVersion3:
return r.Header.Get("Upload-Incomplete") == "?0"
Expand All @@ -1397,7 +1399,7 @@ func setIETFDraftUploadComplete(r *http.Request, resp HTTPResponse, isComplete b
} else {
resp.Header["Upload-Incomplete"] = "?1"
}
case interopVersion4:
case interopVersion4, interopVersion5:
if isComplete {
resp.Header["Upload-Complete"] = "?1"
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func addIETFUploadCompleteHeader(header map[string]string, isComplete bool, inte
} else {
header["Upload-Incomplete"] = "?1"
}
case "4":
case "4", "5":
if isComplete {
header["Upload-Complete"] = "?1"
} else {
Expand Down

0 comments on commit 361b2b4

Please sign in to comment.