could support X-HTTP-Method-Override?
Comment From: zrhmn
It's just my opinion, others may disagree, but I think gin, as a framework should not be accommodating non-standard headers or features, even if they're common in practice.
It is rather trivial to support X-HTTP-Method-Override
in the application.
router.POST("/", func(c *gin.Context) {
methodOverride := c.Request.Header.Get("X-HTTP-Method-Override")
switch methodOverride {
case "", http.MethodPost:
// handlePost(c)
case http.MethodPut:
// handlePut(c)
case http.MethodDelete:
// handleDelete(c)
default:
// handleInvalidMethodOverride ...
}
})
Also, and because this is a non-standard header, everyone would handle it differently and there will be a lot of unnecessary dilemmas that will require solving. For example, per the standard, HTTP GET
method can carry a body but the servers are required to ignore it.
... What do we do if a GET
request carries a X-HTTP-Method-Override: POST
, do we then ignore the standard and read the body?
... What if the request is proxied by a server that enforces the requirement of ignoring the body on GET
requests?
Until there exists standard documented expectation/behavior of a feature like a custom header, frameworks should not be considering proposals for implementing it.
Comment From: Edouard127
Hi, sorry for bringing up this necro issue, but I am having issues with the fact that Java's HttpURLConnection does not recognize the PATCH method as seen at java.net.HttpURLConnection#methods
While I understand that supporting non-standard headers is a reasonable stance, why doesn't Gin provide any methods to handle X-HTTP-Method-Override without messing our code ?
Edit: After seing #3826 I remembered that we can chain multiple HandlerFunc in the endpoints handlers, which allows us to modify the request method beforehand