diff --git a/handler.go b/handler.go index 5935cf3..e46de68 100644 --- a/handler.go +++ b/handler.go @@ -124,7 +124,7 @@ func (handler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Allow overriding the HTTP method. The reason for this is // that some libraries/environments to not support PATCH and // DELETE requests, e.g. Flash in a browser and parts of Java - if newMethod := r.Header.Get("Tus-Method-Override"); newMethod != "" { + if newMethod := r.Header.Get("X-HTTP-Method-Override"); newMethod != "" { r.Method = newMethod } diff --git a/handler_test.go b/handler_test.go index 4187248..818d2bf 100644 --- a/handler_test.go +++ b/handler_test.go @@ -4,6 +4,8 @@ import ( "io" "net/http" "net/http/httptest" + "os" + "strings" "testing" ) @@ -76,3 +78,55 @@ func (test *httpTest) Run(handler http.Handler, t *testing.T) { t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, string(w.Body.Bytes())) } } + +type methodOverrideStore struct { + zeroStore + t *testing.T + called bool +} + +func (s methodOverrideStore) GetInfo(id string) (FileInfo, error) { + if id != "yes" { + return FileInfo{}, os.ErrNotExist + } + + return FileInfo{ + Offset: 5, + Size: 20, + }, nil +} + +func (s *methodOverrideStore) WriteChunk(id string, offset int64, src io.Reader) (int64, error) { + s.called = true + + return 5, nil +} + +func TestMethodOverride(t *testing.T) { + store := &methodOverrideStore{ + t: t, + } + handler, _ := NewHandler(Config{ + DataStore: store, + }) + + (&httpTest{ + Name: "Successful request", + Method: "POST", + URL: "yes", + ReqHeader: map[string]string{ + "Tus-Resumable": "1.0.0", + "Upload-Offset": "5", + "X-HTTP-Method-Override": "PATCH", + }, + ReqBody: strings.NewReader("hello"), + Code: http.StatusNoContent, + ResHeader: map[string]string{ + "Upload-Offset": "10", + }, + }).Run(handler, t) + + if !store.called { + t.Fatal("WriteChunk implementation not called") + } +}