Skip to content

Commit

Permalink
Switch to X-HTTP-Method-Override
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Oct 6, 2015
1 parent 3b43535 commit 7d25a9e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
54 changes: 54 additions & 0 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"io"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
)

Expand Down Expand Up @@ -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")
}
}

0 comments on commit 7d25a9e

Please sign in to comment.