Skip to content

Commit 09f105d

Browse files
authored
Update to RUFH draft 02 (#1027)
* Use Upload-Complete instead of Upload-Incomplete * Increase Upload-Draft-Interop-Version
1 parent b8c7e14 commit 09f105d

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

pkg/handler/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ var DefaultCorsConfig = CorsConfig{
135135
AllowOrigin: regexp.MustCompile(".*"),
136136
AllowCredentials: false,
137137
AllowMethods: "POST, HEAD, PATCH, OPTIONS, GET, DELETE",
138-
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",
138+
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",
139139
MaxAge: "86400",
140-
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",
140+
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",
141141
}
142142

143143
func (config *Config) validate() error {

pkg/handler/cors_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestCORS(t *testing.T) {
2323
},
2424
Code: http.StatusOK,
2525
ResHeader: map[string]string{
26-
"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",
26+
"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",
2727
"Access-Control-Allow-Methods": "POST, HEAD, PATCH, OPTIONS, GET, DELETE",
2828
"Access-Control-Max-Age": "86400",
2929
"Access-Control-Allow-Origin": "https://tus.io",
@@ -40,7 +40,7 @@ func TestCORS(t *testing.T) {
4040
},
4141
ResHeader: map[string]string{
4242
"Access-Control-Allow-Origin": "https://tus.io",
43-
"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",
43+
"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",
4444
"Vary": "Origin",
4545
"Access-Control-Allow-Methods": "",
4646
"Access-Control-Allow-Headers": "",
@@ -72,7 +72,7 @@ func TestCORS(t *testing.T) {
7272
},
7373
Code: http.StatusOK,
7474
ResHeader: map[string]string{
75-
"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",
75+
"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",
7676
"Access-Control-Allow-Methods": "POST, HEAD, PATCH, OPTIONS, GET, DELETE",
7777
"Access-Control-Max-Age": "86400",
7878
"Access-Control-Allow-Origin": "http://tus.io",
@@ -89,7 +89,7 @@ func TestCORS(t *testing.T) {
8989
},
9090
ResHeader: map[string]string{
9191
"Access-Control-Allow-Origin": "http://tus.io",
92-
"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",
92+
"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",
9393
"Vary": "Origin",
9494
"Access-Control-Allow-Methods": "",
9595
"Access-Control-Allow-Headers": "",

pkg/handler/head_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ func TestHead(t *testing.T) {
168168
Method: "HEAD",
169169
URL: "yes",
170170
ReqHeader: map[string]string{
171-
"Upload-Draft-Interop-Version": "3",
171+
"Upload-Draft-Interop-Version": "4",
172172
},
173173
Code: http.StatusNoContent,
174174
ResHeader: map[string]string{
175-
"Upload-Draft-Interop-Version": "3",
176-
"Upload-Incomplete": "?1",
175+
"Upload-Draft-Interop-Version": "4",
176+
"Upload-Complete": "?0",
177177
"Upload-Offset": "5",
178178
},
179179
}).Run(handler, t)
@@ -202,12 +202,12 @@ func TestHead(t *testing.T) {
202202
Method: "HEAD",
203203
URL: "yes",
204204
ReqHeader: map[string]string{
205-
"Upload-Draft-Interop-Version": "3",
205+
"Upload-Draft-Interop-Version": "4",
206206
},
207207
Code: http.StatusNoContent,
208208
ResHeader: map[string]string{
209-
"Upload-Draft-Interop-Version": "3",
210-
"Upload-Incomplete": "?0",
209+
"Upload-Draft-Interop-Version": "4",
210+
"Upload-Complete": "?1",
211211
"Upload-Offset": "10",
212212
},
213213
}).Run(handler, t)
@@ -235,12 +235,12 @@ func TestHead(t *testing.T) {
235235
Method: "HEAD",
236236
URL: "yes",
237237
ReqHeader: map[string]string{
238-
"Upload-Draft-Interop-Version": "3",
238+
"Upload-Draft-Interop-Version": "4",
239239
},
240240
Code: http.StatusNoContent,
241241
ResHeader: map[string]string{
242-
"Upload-Draft-Interop-Version": "3",
243-
"Upload-Incomplete": "?1",
242+
"Upload-Draft-Interop-Version": "4",
243+
"Upload-Complete": "?0",
244244
"Upload-Offset": "5",
245245
},
246246
}).Run(handler, t)

pkg/handler/patch_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,9 @@ func TestPatch(t *testing.T) {
837837
Method: "PATCH",
838838
URL: "yes",
839839
ReqHeader: map[string]string{
840-
"Upload-Draft-Interop-Version": "3",
840+
"Upload-Draft-Interop-Version": "4",
841841
"Upload-Offset": "5",
842-
"Upload-Incomplete": "?0",
842+
"Upload-Complete": "?1",
843843
},
844844
ReqBody: strings.NewReader("hello"),
845845
Code: http.StatusNoContent,
@@ -882,9 +882,9 @@ func TestPatch(t *testing.T) {
882882
Method: "PATCH",
883883
URL: "yes",
884884
ReqHeader: map[string]string{
885-
"Upload-Draft-Interop-Version": "3",
885+
"Upload-Draft-Interop-Version": "4",
886886
"Upload-Offset": "5",
887-
"Upload-Incomplete": "?0",
887+
"Upload-Complete": "?1",
888888
},
889889
ReqBody: strings.NewReader("hello"),
890890
Code: http.StatusNoContent,
@@ -918,9 +918,9 @@ func TestPatch(t *testing.T) {
918918
Method: "PATCH",
919919
URL: "yes",
920920
ReqHeader: map[string]string{
921-
"Upload-Draft-Interop-Version": "3",
921+
"Upload-Draft-Interop-Version": "4",
922922
"Upload-Offset": "5",
923-
"Upload-Incomplete": "?1",
923+
"Upload-Complete": "?0",
924924
},
925925
ReqBody: strings.NewReader("hel"),
926926
Code: http.StatusNoContent,
@@ -954,9 +954,9 @@ func TestPatch(t *testing.T) {
954954
Method: "PATCH",
955955
URL: "yes",
956956
ReqHeader: map[string]string{
957-
"Upload-Draft-Interop-Version": "3",
957+
"Upload-Draft-Interop-Version": "4",
958958
"Upload-Offset": "5",
959-
"Upload-Incomplete": "?1",
959+
"Upload-Complete": "?0",
960960
},
961961
ReqBody: strings.NewReader("hel"),
962962
Code: http.StatusNoContent,

pkg/handler/post_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,15 @@ func TestPost(t *testing.T) {
591591
res := (&httpTest{
592592
Method: "POST",
593593
ReqHeader: map[string]string{
594-
"Upload-Draft-Interop-Version": "3",
595-
"Upload-Incomplete": "?0",
594+
"Upload-Draft-Interop-Version": "4",
595+
"Upload-Complete": "?1",
596596
"Content-Type": "text/plain; charset=utf-8",
597597
"Content-Disposition": "attachment; filename=hello.txt",
598598
},
599599
ReqBody: strings.NewReader("hello world"),
600600
Code: http.StatusCreated,
601601
ResHeader: map[string]string{
602-
"Upload-Draft-Interop-Version": "3",
602+
"Upload-Draft-Interop-Version": "4",
603603
"Location": "http://tus.io/files/foo",
604604
"Upload-Offset": "11",
605605
},
@@ -610,7 +610,7 @@ func TestPost(t *testing.T) {
610610
{
611611
Code: 104,
612612
Header: http.Header{
613-
"Upload-Draft-Interop-Version": []string{"3"},
613+
"Upload-Draft-Interop-Version": []string{"4"},
614614
"Location": []string{"http://tus.io/files/foo"},
615615
"X-Content-Type-Options": []string{"nosniff"},
616616
},
@@ -654,13 +654,13 @@ func TestPost(t *testing.T) {
654654
res := (&httpTest{
655655
Method: "POST",
656656
ReqHeader: map[string]string{
657-
"Upload-Draft-Interop-Version": "3",
658-
"Upload-Incomplete": "?1",
657+
"Upload-Draft-Interop-Version": "4",
658+
"Upload-Complete": "?0",
659659
},
660660
ReqBody: strings.NewReader("hello world"),
661661
Code: http.StatusCreated,
662662
ResHeader: map[string]string{
663-
"Upload-Draft-Interop-Version": "3",
663+
"Upload-Draft-Interop-Version": "4",
664664
"Location": "http://tus.io/files/foo",
665665
"Upload-Offset": "11",
666666
},
@@ -671,7 +671,7 @@ func TestPost(t *testing.T) {
671671
{
672672
Code: 104,
673673
Header: http.Header{
674-
"Upload-Draft-Interop-Version": []string{"3"},
674+
"Upload-Draft-Interop-Version": []string{"4"},
675675
"Location": []string{"http://tus.io/files/foo"},
676676
"X-Content-Type-Options": []string{"nosniff"},
677677
},

pkg/handler/unrouted_handler.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
const UploadLengthDeferred = "1"
20-
const currentUploadDraftInteropVersion = "3"
20+
const currentUploadDraftInteropVersion = "4"
2121

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

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

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

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

@@ -773,7 +773,7 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
773773
return
774774
}
775775

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

0 commit comments

Comments
 (0)