My goal is to render an HTTP response in a Grails 3.1 controller method that has
- a given status code (mostly
204
, but potentially others, like200
) - no
Content-Type
, orContent-Encoding
headers (since there is no content, right?)
render(status: 204)
adds an arbitrary Content-Type: application/json
header.
Furthermore, this method (see grails.artefact.controller.support.ResponseRenderer.render()
) in this case invokes HttpServletResponse.sendError()
, though it is not an error. Why is that?
Currently we solve this by dealing with the response
directly:
response.status = statusCode.value()
response.flushBuffer()
But this prevents us from using Grails interceptors after
method for doing something before the response is sent. This is why we are looking for a different way, which does not change the HTTP response (like adding a Content-Type
header).