Tomcat 7 (unsure if this is a problem on other versions) seems to intermittently fail to apply gzip compression.
I find that it wont work for a particular start/deployment but then stopping and starting the service may cause it to start working again.
So it either seems to work or not based on a particular start. This has been driving me crazy for basically a full day and a half now and I was mucking around with configs etc but with no changes I can repeatedly (must have checked this about 20-30 times now just to ensure I'm not imagining things (It's been a long day!)) get it work/not work just by stopping and starting the tomcat service. The probability of it gzipping stuff is approximately 50% - at first I thought it was reliably following a work/doesn't work pattern but occasionally you'll get it working a few times in a row.
I've been through the logs with a fine toothcomb and there's nothing indicating there being something wrong with any of the start ups.
Interestingly I have a different server where it doesnt work at all with the same basic configuration (which I've been diffing all day to rule out the different variables there). The only real difference left is that one has a lot more apps on it (its our build server, whereas the other one is my machine), which leads me to wonder if there's some kindof race that gets negatively effected by having a lot of apps to load.
I've also experimented with using NIO (the non blocking connector) and useSendfile="false"
(which is ignored if using the normal blocking one as the catalina logs will inform you) but this seems to suffer from the same problem.
Really stumped by this.
Some of the resources/things I've tried:
also none of the above help me understand the difference between the two machines. On the build server we are using dynamic loading for the most part whereas on my machine I just use hard coded Contexts. I feel like I've ruled that out though as I set up a hard coded context on the server which also didnt work.
Another thing I've noticed come up a lot is people talking about using apache and tomcat together and then needing to do the compression in apache. We aren't doing that! It's just tomcat.
EDIT
I've just stumbled across this post which prompted my to try the compression using a browser on the server... the compression is working on there! Not sure what to make of that!
EDIT
on further reflection the browser I used on the server was chrome as firefox isn't installed - it's possible that this reliably reports what is going on with the headers... I think I'm going to stick to curl + wireshark in the future though!