Skip to content

Commit

Permalink
Dataprovider now support method override (cs3org#792)
Browse files Browse the repository at this point in the history
The TUS protocol requires the ability to override the PATCH and DELETE
methods using the X-HTTP-Method-Override.

These were added in the data provider.
  • Loading branch information
Vincent Petry authored and David Christofas committed Jun 29, 2020
1 parent f29ad4b commit c2c5f2b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/http/services/dataprovider/dataprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ func (s *svc) setHandler() (err error) {
log := appctx.GetLogger(r.Context())
log.Info().Msgf("tusd routing: path=%s", r.URL.Path)

switch r.Method {
method := r.Method
// https://github.com/tus/tus-resumable-upload-protocol/blob/master/protocol.md#x-http-method-override
if r.Header.Get("X-HTTP-Method-Override") != "" {
method = r.Header.Get("X-HTTP-Method-Override")
}

switch method {
// old fashioned download.

// GET is not part of the tus.io protocol
Expand Down Expand Up @@ -164,7 +170,13 @@ func (s *svc) setHandler() (err error) {
}))
} else {
s.handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
method := r.Method
// https://github.com/tus/tus-resumable-upload-protocol/blob/master/protocol.md#x-http-method-override
if r.Header.Get("X-HTTP-Method-Override") != "" {
method = r.Header.Get("X-HTTP-Method-Override")
}

switch method {
case "HEAD":
w.WriteHeader(http.StatusOK)
return
Expand Down

0 comments on commit c2c5f2b

Please sign in to comment.