Do not reject unexpected content types during upload creation

See tus/tus-java-client#10
This commit is contained in:
Marius 2016-09-29 21:20:51 +02:00
parent d6ccb0fbb8
commit 182a96e3e8
2 changed files with 13 additions and 12 deletions

View File

@ -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{

View File

@ -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.