Should I explicitly not send response body for HEAD requests? #2286
-
Hello! I've just implemented a route that handles both GET and HEAD requests for verifying the user token (stored on cookies). I am aware that the server should return an empty body for HEAD requests but just out of curiosity I tried sending it and.. it just worked. no errors. So I'm left wondering if I should explicitly use a NoContent() for HEAD requests, like this: if c.Request().Method == http.MethodHead {
return c.NoContent(http.StatusOK)
}
return c.JSON(http.StatusOK, echo.Map{"message": "Valid token"}) ...or if it doesn't matter (because Echo seems to handle it automatically) and I can just point both routes to the same handler without changing it? I've looked through the source code to see where this could be handled but the only (vaguely related) method check I could find was this one, and it seems to be for default error responses so I don't see how it would intercept Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I've included the No filtering: So I should definitely filter it out. Good to know! |
Beta Was this translation helpful? Give feedback.
I've included the
${bytes_out}
tag in my logging format and it seems Echo in fact does not implicitly filter out the response body:No filtering:
26 bytes_out
With filtering:
0 bytes_out
So I should definitely filter it out. Good to know!