Skip to content

Commit

Permalink
Correct parsing Upload-Concat for final uplaods
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Jan 31, 2017
1 parent b05382e commit 7710fd7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
11 changes: 7 additions & 4 deletions concat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func TestConcat(t *testing.T) {
Method: "POST",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
// A space between `final;` and the first URL should be allowed due to
// compatibility reasons, even if the specification does not define
// it. Therefore this character is included in this test case.
"Upload-Concat": "final; http://tus.io/files/a /files/b/",
},
Code: http.StatusCreated,
Expand Down Expand Up @@ -153,7 +156,7 @@ func TestConcat(t *testing.T) {
},
Code: http.StatusOK,
ResHeader: map[string]string{
"Upload-Concat": "final; http://tus.io/files/a http://tus.io/files/b",
"Upload-Concat": "final;http://tus.io/files/a http://tus.io/files/b",
"Upload-Length": "10",
"Upload-Offset": "10",
},
Expand All @@ -178,7 +181,7 @@ func TestConcat(t *testing.T) {
Method: "POST",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
"Upload-Concat": "final; http://tus.io/files/c",
"Upload-Concat": "final;http://tus.io/files/c",
},
Code: http.StatusBadRequest,
}).Run(handler, t)
Expand All @@ -200,7 +203,7 @@ func TestConcat(t *testing.T) {
Method: "POST",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
"Upload-Concat": "final; /files/huge",
"Upload-Concat": "final;/files/huge",
},
Code: http.StatusRequestEntityTooLarge,
}).Run(handler, t)
Expand Down Expand Up @@ -240,7 +243,7 @@ func TestConcat(t *testing.T) {
URL: "",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
"Upload-Concat": "final; ",
"Upload-Concat": "final;",
},
Code: http.StatusBadRequest,
}).Run(handler, t)
Expand Down
2 changes: 1 addition & 1 deletion post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestPost(t *testing.T) {
"Tus-Resumable": "1.0.0",
"Upload-Length": "300",
"Content-Type": "application/offset+octet-stream",
"Upload-Concat": "final; http://tus.io/files/a http://tus.io/files/b",
"Upload-Concat": "final;http://tus.io/files/a http://tus.io/files/b",
},
ReqBody: strings.NewReader("hello"),
Code: http.StatusForbidden,
Expand Down
11 changes: 7 additions & 4 deletions unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,11 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
if info.IsFinal {
v := "final;"
for _, uploadID := range info.PartialUploads {
v += " " + handler.absFileURL(r, uploadID)
v += handler.absFileURL(r, uploadID) + " "
}
// Remove trailing space
v = v[:len(v)-1]

w.Header().Set("Upload-Concat", v)
}

Expand Down Expand Up @@ -782,7 +785,7 @@ func serializeMeta(meta map[string]string) string {

// Parse the Upload-Concat header, e.g.
// Upload-Concat: partial
// Upload-Concat: final; http://tus.io/files/a /files/b/
// Upload-Concat: final;http://tus.io/files/a /files/b/
func parseConcat(header string) (isPartial bool, isFinal bool, partialUploads []string, err error) {
if len(header) == 0 {
return
Expand All @@ -793,8 +796,8 @@ func parseConcat(header string) (isPartial bool, isFinal bool, partialUploads []
return
}

l := len("final; ")
if strings.HasPrefix(header, "final; ") && len(header) > l {
l := len("final;")
if strings.HasPrefix(header, "final;") && len(header) > l {
isFinal = true

list := strings.Split(header[l:], " ")
Expand Down

0 comments on commit 7710fd7

Please sign in to comment.