Request body not parsed when using X-HTTP-Method-Override header
netrounds-guillaume opened this issue Β· comments
π Bug Report
There is a bug around this code:
Lines 324 to 330 in 1c444cc
r.Method
is overridden to GET
before r.ParseForm()
which causes ParseForm
to skip parsing the request body and goes straight to parsing from the query string parameters. Since the whole point of using X-HTTP-Method-Override
is to move the query string parameters to the request body, no query string parameters are present in the URL
One possible solution is to move r.Method = strings.ToUpper(override)
after the r.ParseForm()
block.
To Reproduce
Send a POST
request to a GET
endpoint with Content-Type: application/x-www-form-urlencoded
and X-HTTP-Method-Override: GET
headers. Set the request body with what would be query string parameters e.g. limit=15&page=1
Expected behavior
Form parameters are parsed and passed along to the API handler
Actual Behavior
Form parameters are not parsed and none of the parameters are populated when reaching the API handler
Your Environment
(no info)
Hi, thanks for the detailed issue! The problem as you describe it seems indeed to be that we're mutating the request before parsing. Would you be willing to contribute a PR with a fix and a test confirming the fix?