Skip to content

Commit

Permalink
fix: handle x-http-method-override for PATCH as POST (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 authored Mar 7, 2023
1 parent b94ecfc commit 4070ce3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions util/genrest/goviewcreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ func NewView(model *gomodel.Model) (*goview.View, error) {

for _, handler := range registered {
file.P(` router.HandleFunc(%q, rest.%s).Methods(%q)`, handler.pattern, handler.function, handler.verb)
// Java's PATCH requests are sent as POST requests with a `X-HTTP-Method-Override` header
if handler.verb == "PATCH" {
// HeadersRegexp is used to match for both POST Http Verb and the Header value
file.P(` router.HandleFunc(%q, rest.%s).HeadersRegexp("X-HTTP-Method-Override", "^PATCH$").Methods("POST")`, handler.pattern, handler.function)
}
}
file.P(` router.PathPrefix("/").HandlerFunc(rest.catchAllHandler)`)
file.P(`}`)
Expand Down

0 comments on commit 4070ce3

Please sign in to comment.