Skip to content

Commit

Permalink
Update to RUFH draft 02 (#1027)
Browse files Browse the repository at this point in the history
* Use Upload-Complete instead of Upload-Incomplete

* Increase Upload-Draft-Interop-Version
  • Loading branch information
Acconut authored Nov 4, 2023
1 parent b8c7e14 commit 09f105d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pkg/handler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ var DefaultCorsConfig = CorsConfig{
AllowOrigin: regexp.MustCompile(".*"),
AllowCredentials: false,
AllowMethods: "POST, HEAD, PATCH, OPTIONS, GET, DELETE",
AllowHeaders: "Authorization, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Incomplete, Upload-Draft-Interop-Version",
AllowHeaders: "Authorization, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Complete, Upload-Draft-Interop-Version",
MaxAge: "86400",
ExposeHeaders: "Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Incomplete, Upload-Draft-Interop-Version",
ExposeHeaders: "Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Complete, Upload-Draft-Interop-Version",
}

func (config *Config) validate() error {
Expand Down
8 changes: 4 additions & 4 deletions pkg/handler/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestCORS(t *testing.T) {
},
Code: http.StatusOK,
ResHeader: map[string]string{
"Access-Control-Allow-Headers": "Authorization, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Incomplete, Upload-Draft-Interop-Version",
"Access-Control-Allow-Headers": "Authorization, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Complete, Upload-Draft-Interop-Version",
"Access-Control-Allow-Methods": "POST, HEAD, PATCH, OPTIONS, GET, DELETE",
"Access-Control-Max-Age": "86400",
"Access-Control-Allow-Origin": "https://tus.io",
Expand All @@ -40,7 +40,7 @@ func TestCORS(t *testing.T) {
},
ResHeader: map[string]string{
"Access-Control-Allow-Origin": "https://tus.io",
"Access-Control-Expose-Headers": "Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Incomplete, Upload-Draft-Interop-Version",
"Access-Control-Expose-Headers": "Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Complete, Upload-Draft-Interop-Version",
"Vary": "Origin",
"Access-Control-Allow-Methods": "",
"Access-Control-Allow-Headers": "",
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestCORS(t *testing.T) {
},
Code: http.StatusOK,
ResHeader: map[string]string{
"Access-Control-Allow-Headers": "Authorization, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Incomplete, Upload-Draft-Interop-Version",
"Access-Control-Allow-Headers": "Authorization, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Complete, Upload-Draft-Interop-Version",
"Access-Control-Allow-Methods": "POST, HEAD, PATCH, OPTIONS, GET, DELETE",
"Access-Control-Max-Age": "86400",
"Access-Control-Allow-Origin": "http://tus.io",
Expand All @@ -89,7 +89,7 @@ func TestCORS(t *testing.T) {
},
ResHeader: map[string]string{
"Access-Control-Allow-Origin": "http://tus.io",
"Access-Control-Expose-Headers": "Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Incomplete, Upload-Draft-Interop-Version",
"Access-Control-Expose-Headers": "Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata, Upload-Defer-Length, Upload-Concat, Upload-Complete, Upload-Draft-Interop-Version",
"Vary": "Origin",
"Access-Control-Allow-Methods": "",
"Access-Control-Allow-Headers": "",
Expand Down
18 changes: 9 additions & 9 deletions pkg/handler/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ func TestHead(t *testing.T) {
Method: "HEAD",
URL: "yes",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
},
Code: http.StatusNoContent,
ResHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Incomplete": "?1",
"Upload-Draft-Interop-Version": "4",
"Upload-Complete": "?0",
"Upload-Offset": "5",
},
}).Run(handler, t)
Expand Down Expand Up @@ -202,12 +202,12 @@ func TestHead(t *testing.T) {
Method: "HEAD",
URL: "yes",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
},
Code: http.StatusNoContent,
ResHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Incomplete": "?0",
"Upload-Draft-Interop-Version": "4",
"Upload-Complete": "?1",
"Upload-Offset": "10",
},
}).Run(handler, t)
Expand Down Expand Up @@ -235,12 +235,12 @@ func TestHead(t *testing.T) {
Method: "HEAD",
URL: "yes",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
},
Code: http.StatusNoContent,
ResHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Incomplete": "?1",
"Upload-Draft-Interop-Version": "4",
"Upload-Complete": "?0",
"Upload-Offset": "5",
},
}).Run(handler, t)
Expand Down
16 changes: 8 additions & 8 deletions pkg/handler/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,9 @@ func TestPatch(t *testing.T) {
Method: "PATCH",
URL: "yes",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
"Upload-Offset": "5",
"Upload-Incomplete": "?0",
"Upload-Complete": "?1",
},
ReqBody: strings.NewReader("hello"),
Code: http.StatusNoContent,
Expand Down Expand Up @@ -882,9 +882,9 @@ func TestPatch(t *testing.T) {
Method: "PATCH",
URL: "yes",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
"Upload-Offset": "5",
"Upload-Incomplete": "?0",
"Upload-Complete": "?1",
},
ReqBody: strings.NewReader("hello"),
Code: http.StatusNoContent,
Expand Down Expand Up @@ -918,9 +918,9 @@ func TestPatch(t *testing.T) {
Method: "PATCH",
URL: "yes",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
"Upload-Offset": "5",
"Upload-Incomplete": "?1",
"Upload-Complete": "?0",
},
ReqBody: strings.NewReader("hel"),
Code: http.StatusNoContent,
Expand Down Expand Up @@ -954,9 +954,9 @@ func TestPatch(t *testing.T) {
Method: "PATCH",
URL: "yes",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
"Upload-Offset": "5",
"Upload-Incomplete": "?1",
"Upload-Complete": "?0",
},
ReqBody: strings.NewReader("hel"),
Code: http.StatusNoContent,
Expand Down
16 changes: 8 additions & 8 deletions pkg/handler/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,15 @@ func TestPost(t *testing.T) {
res := (&httpTest{
Method: "POST",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Incomplete": "?0",
"Upload-Draft-Interop-Version": "4",
"Upload-Complete": "?1",
"Content-Type": "text/plain; charset=utf-8",
"Content-Disposition": "attachment; filename=hello.txt",
},
ReqBody: strings.NewReader("hello world"),
Code: http.StatusCreated,
ResHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
"Location": "http://tus.io/files/foo",
"Upload-Offset": "11",
},
Expand All @@ -610,7 +610,7 @@ func TestPost(t *testing.T) {
{
Code: 104,
Header: http.Header{
"Upload-Draft-Interop-Version": []string{"3"},
"Upload-Draft-Interop-Version": []string{"4"},
"Location": []string{"http://tus.io/files/foo"},
"X-Content-Type-Options": []string{"nosniff"},
},
Expand Down Expand Up @@ -654,13 +654,13 @@ func TestPost(t *testing.T) {
res := (&httpTest{
Method: "POST",
ReqHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Incomplete": "?1",
"Upload-Draft-Interop-Version": "4",
"Upload-Complete": "?0",
},
ReqBody: strings.NewReader("hello world"),
Code: http.StatusCreated,
ResHeader: map[string]string{
"Upload-Draft-Interop-Version": "3",
"Upload-Draft-Interop-Version": "4",
"Location": "http://tus.io/files/foo",
"Upload-Offset": "11",
},
Expand All @@ -671,7 +671,7 @@ func TestPost(t *testing.T) {
{
Code: 104,
Header: http.Header{
"Upload-Draft-Interop-Version": []string{"3"},
"Upload-Draft-Interop-Version": []string{"4"},
"Location": []string{"http://tus.io/files/foo"},
"X-Content-Type-Options": []string{"nosniff"},
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const UploadLengthDeferred = "1"
const currentUploadDraftInteropVersion = "3"
const currentUploadDraftInteropVersion = "4"

var (
reExtractFileID = regexp.MustCompile(`([^/]+)\/?$`)
Expand Down Expand Up @@ -434,7 +434,7 @@ func (handler *UnroutedHandler) PostFileV2(w http.ResponseWriter, r *http.Reques
// Parse headers
contentType := r.Header.Get("Content-Type")
contentDisposition := r.Header.Get("Content-Disposition")
isComplete := r.Header.Get("Upload-Incomplete") == "?0"
isComplete := r.Header.Get("Upload-Complete") == "?1"

info := FileInfo{
MetaData: make(MetaData),
Expand Down Expand Up @@ -652,9 +652,9 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
} else {
if !info.SizeIsDeferred && info.Offset == info.Size {
// Upload is complete if we know the size and it matches the offset.
resp.Header["Upload-Incomplete"] = "?0"
resp.Header["Upload-Complete"] = "?1"
} else {
resp.Header["Upload-Incomplete"] = "?1"
resp.Header["Upload-Complete"] = "?0"
}

resp.Header["Upload-Draft-Interop-Version"] = currentUploadDraftInteropVersion
Expand Down Expand Up @@ -726,7 +726,7 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
return
}

// TODO: If Upload-Incomplete: ?0 and Content-Length is set, we can
// TODO: If Upload-Complete: ?1 and Content-Length is set, we can
// - declare the length already here
// - validate that the length from this request matches info.Size if !info.SizeIsDeferred

Expand Down Expand Up @@ -773,7 +773,7 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
return
}

isComplete := r.Header.Get("Upload-Incomplete") == "?0"
isComplete := r.Header.Get("Upload-Complete") == "?1"
if isComplete && info.SizeIsDeferred {
info, err = upload.GetInfo(c)
if err != nil {
Expand Down

0 comments on commit 09f105d

Please sign in to comment.