8

I'm trying to enable http response compression on Spring boot web application. It works for some user-agents, and for some reason doesn't for others (specific cases below).

My basic question is: Why http response compression (gzip) in Spring Boot works only for some User-Agent headers and where it is configured.

Spring boot reference doesn't say anything about it.

I prepared simple web application with enabled compression: sample spring-boot-compression app There are integration tests that verify that gzip encoding works for some cases only.

I configured spring boot with:

server:
  tomcat:
    compression: on
    compressable-mime-types: text/html,text/css,application/javascript,application/json,application/font-sfnt,application/font-woff,application/font-woff2

When I try to do some requests with curl:

$ curl -i -H "Accept-Encoding: gzip,deflate" http://localhost:8080
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding

I see that Content-Encoding: gzip header is set.

When I setUser-Agent to AppleWebKit (or some other browsers like IE) it does not compress:

$ curl -i -H "Accept-Encoding: gzip,deflate" -H "User-Agent: AppleWebKit" http://localhost:8080
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Vary: Accept-Encoding

I repeated my tests with some other browsers and User-Agent header modification and received some strange results.

Here some of working (response is compressed) User-Agent headers:

- Mozilla/5.0
- Mozilla/5.0 (Windows NT 6.1; WOW64) Chrome/46.0.2490.80 Safari/537.36
- Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Firefox/34.0
- SomeUnknownBrowser

Some of not working User-Agent headers:

 - AppleWebKit
 - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
 - Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
 - Gecko/20100101

I also tried to use compression with GzipFilter and it behaves exactly the same. Also tried embedded Jetty instead of Tomcat - same result.

Maybe I'm just missing something.

ssobocik
  • 155
  • 3
  • 8

2 Answers2

10

You're probably using some sort of antivirus (maybe ESET). Try turning off HTTP protection.

With Eset you can try something like: Advanced -> Internet and email -> Web Access Protection - turn off.

gmaslowski
  • 774
  • 5
  • 13
  • Your answer is correct. The problem was not on a server side, but on my client machine (Windows 7 with ESET antivirus). It turned out, that response (checked with Wireshark) was being received gzipped, and somewhere between network interface na browser 'something' was unzipping it. That 'something' was ESET. – ssobocik Nov 06 '15 at 12:10
  • ****** ESET! MF pointless "security" when accessing localhost addresses! – Stefan Dragnev Jan 16 '17 at 12:51
  • But what does it have to do with AppleWebKit? I can (unwillingly) accept that ESET is sticking its nose in, but just for AppleWebKit ?!!! Make no sense. – ianbeks May 11 '17 at 15:39
  • @ianbeks You're right, it would be weird. I think we would have to ask ssobocik if all of the tests were done solely on his machine. – gmaslowski Jul 14 '17 at 13:44
0

This worked for me with Spring 1.4

 server.compression.enabled: true
server.compression.mime-types: application/json,application/xml,text/html,text/xml,text/plain,text/css,application/javascript
Ronny Shibley
  • 2,030
  • 22
  • 25