-
Bug
-
Resolution: Done
-
Major
-
3.0.21.Final, 3.6.2.Final
-
None
-
None
Suppose that endpoint handler manipulates with HttpServletResponse directly and returns no entity:
@GET @Path("/data") public void getData(@Context HttpServletResponse response) { response.setStatus(200); response.getOutputStream().write(...); }
In this case unfortunately ServerResponseWriter overwrites status code to 204 (see line 91), which is not desired, as the client gets HTTP 204 and non-empty body (note that body is small enough to be buffered).
Is it possible for ServerResponseWriter to learn that the body is already written? If not, consider the following workaround in which the handler should commit the response:
@GET @Path("/data") public void getData(@Context HttpServletResponse response) { response.setStatus(200); response.getOutputStream().write(...); response.flushBuffer(); // will commit the response }
In this case the corresponding code in ServerResponseWriter can be:
if (jaxrsResponse.getEntity() == null || response.getOutputStream() == null) { if (!response.isCommitted()) { // If response is already committed then setting the status/headers has no effect: response.setStatus(jaxrsResponse.getStatus()); commitHeaders(jaxrsResponse, response); } return; }
- is cloned by
-
RESTEASY-2871 ServerResponseWriter sets HTTP status 204 even though response was written to HttpServletResponse
- Open