On Tue, Apr 27, 2021 at 7:05 PM Mark Thomas <ma...@apache.org> wrote:
> Hi all, > > I've started to look at this and I am struggling to see a way to > implement something that looks like mod_headers as a Filter. > > Request headers are fairly simple. The process looks something like: > a) take a copy of all the headers received > b) apply all the rules for request headers > c) wrap the request, overriding the various getHeader... methods and > return values appropriate for the modified set of headers > > Response headers are where I am currently stuck. > A similar model to request headers might look like: > a) wrap the response > b) intercept all the headers set by the application > c) apply all the rules for response headers > d) call the appropriate setHeader... methods on the wrapped response > for the modified set of headers > > The problem is that d) (and hence c) needs to be done immediately before > the response is committed and - short of buffering the entire response > body - there is no way to know when that is going to happen. > > Is the answer we need to buffer the entire response body? > > Any cunning ideas on how to detect (in a Filter or wrapped response) > that the response is about to be committed? > > I guess we could try and track bytes (about to be) written and compare > that to the known buffer size. That seems a little fragile on first > impression. > > Another option is to abandon the mod_headers clone aim and do something > simpler along the lines of blocking applications from setting specific > headers and/or header/value combinations. > > Thoughts? > I remember after doing the rewrite valve I got asked a bit about mod_headers because "why not". However, now I recall I found out it would be far less practical. So I very quickly moved on since it was also less useful than rewrite. I would still probably not do it. Rémy > > Mark > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > >