I need to minimize Tomcat's response header. The device sending requests to tomcat is very limited in memory, so I want to remove the headers Date, Server and Content-Type. I set up my own valve with an action hook. The hook gets called, but it seems to be impossible to remove the date and server header.
First I executed my method only when ActionCode == COMMIT
- didn't work.
Strange. So I looked in the Tomcat source code: In the method action() of Tomcat's AbstractHttp11Processor
when ActionCode==COMMIT
prepareResponse()
is called (which set's the server and date headers) and then- it writes the headers to the output buffer.
So it is not possible to intercept. When I set the headers before this action gets called they get overwritten in the AbstractHttp11Processor
. When I set the headers after that, they will be ignored, as they were already written to the buffer. My only chance seems to be to reset the output buffer and write the headers to the buffer or is there a better way? And is it even possible to do that?