Skip to content

Commit 0b983a1

Browse files
authored
adds support for X-HTTP-Method-Override header (#19)
- switches request method to the one specified in the `X-HTTP-Method-Override` header, which is useful for dumb clients that have no native support for `PUT`, `PATCH`, or `DELETE` fixes #5
1 parent c65738e commit 0b983a1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

middleware.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ func (api *API) RecoveryMiddleware(h http.Handler) http.Handler {
4848
func (api *API) CompressionMiddleware(h http.Handler) http.Handler {
4949
return handlers.CompressHandlerLevel(h, api.conf.GzipLevel)
5050
}
51+
52+
// MethodOverrideMiddleware allows clients who can not perform native PUT, PATCH,
53+
// or DELETE requests to specify the HTTP method in the X-HTTP-Method-Override
54+
// header. The header name is case sensitive.
55+
func (api *API) MethodOverrideMiddleware(h http.Handler) http.Handler {
56+
return handlers.HTTPMethodOverrideHandler(h)
57+
}

middleware_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ func (suite *HyperdriveTestSuite) TestRecoveryMiddleware() {
1717
func (suite *HyperdriveTestSuite) TestCompressionMiddleware() {
1818
suite.Implements((*http.Handler)(nil), suite.TestAPI.CompressionMiddleware(suite.TestHandler), "return an implementation of http.Handler")
1919
}
20+
21+
func (suite *HyperdriveTestSuite) TestMethodOverrideMiddleware() {
22+
suite.Implements((*http.Handler)(nil), suite.TestAPI.MethodOverrideMiddleware(suite.TestHandler), "return an implementation of http.Handler")
23+
}

0 commit comments

Comments
 (0)