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

@ -201,10 +201,16 @@ func TestPostWithUpload(t *testing.T) {
Method: "POST", Method: "POST",
ReqHeader: map[string]string{ ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0", "Tus-Resumable": "1.0.0",
"Upload-Length": "300",
"Upload-Metadata": "foo aGVsbG8=, bar d29ybGQ=",
"Content-Type": "application/false", "Content-Type": "application/false",
}, },
ReqBody: strings.NewReader("hello"), 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) }).Run(handler, t)
(&httpTest{ (&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 // PostFile creates a new file upload using the datastore after validating the
// length and parsing the metadata. // length and parsing the metadata.
func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) { func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) {
// Check for presence of application/offset+octet-stream // Check for presence of application/offset+octet-stream. If another content
containsChunk := false // type is defined, it will be ignored and treated as none was set because
if contentType := r.Header.Get("Content-Type"); contentType != "" { // some HTTP clients may enforce a default value for this header.
if contentType != "application/offset+octet-stream" { containsChunk := r.Header.Get("Content-Type") == "application/offset+octet-stream"
handler.sendError(w, r, ErrInvalidContentType)
return
}
containsChunk = true
}
// Only use the proper Upload-Concat header if the concatenation extension // Only use the proper Upload-Concat header if the concatenation extension
// is even supported by the data store. // is even supported by the data store.