From 182a96e3e8c6ef287114b695bbceb6568e00ea0c Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 29 Sep 2016 21:20:51 +0200 Subject: [PATCH] Do not reject unexpected content types during upload creation See tus/tus-java-client#10 --- post_test.go | 12 +++++++++--- unrouted_handler.go | 13 ++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/post_test.go b/post_test.go index ea91f21..ae0a3d1 100644 --- a/post_test.go +++ b/post_test.go @@ -200,11 +200,17 @@ func TestPostWithUpload(t *testing.T) { Name: "Incorrect content type", Method: "POST", ReqHeader: map[string]string{ - "Tus-Resumable": "1.0.0", - "Content-Type": "application/false", + "Tus-Resumable": "1.0.0", + "Upload-Length": "300", + "Upload-Metadata": "foo aGVsbG8=, bar d29ybGQ=", + "Content-Type": "application/false", }, ReqBody: strings.NewReader("hello"), - Code: http.StatusBadRequest, + Code: http.StatusCreated, + ResHeader: map[string]string{ + "Location": "http://tus.io/files/foo", + "Upload-Offset": "", + }, }).Run(handler, t) (&httpTest{ diff --git a/unrouted_handler.go b/unrouted_handler.go index 514060c..8442aec 100644 --- a/unrouted_handler.go +++ b/unrouted_handler.go @@ -190,15 +190,10 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler { // PostFile creates a new file upload using the datastore after validating the // length and parsing the metadata. func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) { - // Check for presence of application/offset+octet-stream - containsChunk := false - if contentType := r.Header.Get("Content-Type"); contentType != "" { - if contentType != "application/offset+octet-stream" { - handler.sendError(w, r, ErrInvalidContentType) - return - } - containsChunk = true - } + // Check for presence of application/offset+octet-stream. If another content + // type is defined, it will be ignored and treated as none was set because + // some HTTP clients may enforce a default value for this header. + containsChunk := r.Header.Get("Content-Type") == "application/offset+octet-stream" // Only use the proper Upload-Concat header if the concatenation extension // is even supported by the data store.