I realized that it is impossible to add more headers to the HttpServletResponse after starting to write the response body to the output buffer, which, I think, in some random universe may make sense, although everything is still stored in memory.
Now the question is: is there any trick to get around this anyway? Clearly, since the resetBuffer() function is available, which allows you to clear the content body without clearing the headers, there must be some way for the HttpServletResponse object to return to a state in which it is possible to write more headers. Is there, for example, a way to read the content body, clear it with resetBuffer() , set more headers and then restore the content body?
Beyond : The reason I would like to do this is to add a header as the very last step in my servlet, which tells me how long the server is busy processing the request.
source share