Switch to X-HTTP-Method-Override
This commit is contained in:
parent
3b4353578d
commit
7d25a9e65b
|
@ -124,7 +124,7 @@ func (handler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// Allow overriding the HTTP method. The reason for this is
|
// Allow overriding the HTTP method. The reason for this is
|
||||||
// that some libraries/environments to not support PATCH and
|
// that some libraries/environments to not support PATCH and
|
||||||
// DELETE requests, e.g. Flash in a browser and parts of Java
|
// 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
|
r.Method = newMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"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()))
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue