title: Spring boot response compression not working
body: <p>I have some javascript bundled file that is pretty big, ~1MB.
  I'm trying to turn on response compression with the following application properties in my yml file:</p>
  
  <pre><code>server.compression.enabled: true
  server.compression.mime-types: application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css
  </code></pre>
  
  <p>But it doesn't work. No compression is happening. </p>
  
  <p>Request headers:</p>
  
  <pre><code>Connection: keep-alive
  Pragma: no-cache
  Cache-Control: no-cache
  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
  Accept: */*
  Accept-Encoding: gzip, deflate, sdch, br
  </code></pre>
  
  <p>Response headers</p>
  
  <pre><code>Cache-Control:no-cache, no-store, max-age=0, must-revalidate
  Connection:keep-alive
  Content-Length:842821
  Content-Type:application/javascript;charset=UTF-8
  </code></pre>
  
  <p>There's no content encoding header in the response.</p>
  
  <p>I'm using spring boot version 1.3.5.RELEASE</p>
  
  <p>What am I missing?</p>
  
  <p>=== EDIT 4 ===
  I was planning to create a stand alone app to investigate further why content compression properties weren't working.
  But all of sudden it started working and I haven't changed any thing configuration-wise, not POM file change, not application.yml file change. So I don't know what has changed that made it working...</p>
  
  <p><strong>===EDIT 3===</strong>
  follow @chimmi's suggestions further. I've put break points in the suggested places. It looks like requests to static resources (js files) never stopped at those break points. Only rest API requests do. And for those request, the content-length was zero for some reason which causes the content compression to be skipped.</p>
  
  <p><a href="https://i.stack.imgur.com/7oBeh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7oBeh.png" alt="enter image description here"></a></p>
  
  <p><strong>===EDIT 2===</strong>
  I've put a break point at line 180 of o.s.b.a.w.ServerProperties thanks to @chimmi's suggestion and it shows that all the properties are set but somehow the server doesn't honor the setting... :(</p>
  
  <p><a href="https://i.stack.imgur.com/zRUZU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zRUZU.png" alt="Printing the Compression object at o.s.b.a.w.ServerProperties line 180 "></a></p>
  
  <p><strong>===EDIT 1===</strong></p>
  
  <p>not sure if it matters, but I'm pasting my application main and configuration code here:</p>
  
  <p>Application.java:</p>
  
  <pre><code>@SpringBootApplication
  public class TuangouApplication extends SpringBootServletInitializer {
  
      public static void main(String[] args) throws Exception {
          SpringApplication.run(TuangouApplication.class, args);
      }
  
      // this is for WAR file deployment
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(TuangouApplication.class);
      }
  
      @Bean
      public javax.validation.Validator localValidatorFactoryBean() {
         return new LocalValidatorFactoryBean();
      }
  }
  </code></pre>
  
  <p>Configuration:</p>
  
  <pre><code>@Configuration
  public class TuangouConfiguration extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          // @formatter:off   
          http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**").permitAll()
              .and().antMatcher("/**").authorizeRequests().antMatchers("/api/**").permitAll()
              .and().exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/"))
              .and().formLogin().loginPage("/login").failureUrl("/login?error").permitAll()
              .and().logout().logoutSuccessUrl("/").permitAll()
              .and().csrf().csrfTokenRepository(csrfTokenRepository())
              .and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
              .headers().defaultsDisabled().cacheControl();
          // @formatter:on
      }
  
      @Order(Ordered.HIGHEST_PRECEDENCE)
      @Configuration
      @EnableGlobalMethodSecurity(prePostEnabled=true)
      protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {
  
          @Override
          public void init(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userDetailsService()).passwordEncoder(new BCryptPasswordEncoder());
          }
  
          @Bean
          public UserDetailsService userDetailsService() {
              return new DatabaseUserServiceDetails();
          }
      }
  
      private Filter csrfHeaderFilter() {
          return new OncePerRequestFilter() {
              @Override
              protected void doFilterInternal(HttpServletRequest request,
                      HttpServletResponse response, FilterChain filterChain)
                              throws ServletException, IOException {
                  CsrfToken csrf = (CsrfToken) request
                          .getAttribute(CsrfToken.class.getName());
                  if (csrf != null) {
                      Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                      String token = csrf.getToken();
                      if (cookie == null
                              || token != null &amp;&amp; !token.equals(cookie.getValue())) {
                          cookie = new Cookie("XSRF-TOKEN", token);
                          cookie.setPath("/");
                          response.addCookie(cookie);
                      }
                  }
                  filterChain.doFilter(request, response);
              }
          };
      }
  
      private CsrfTokenRepository csrfTokenRepository() {
          HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
          repository.setHeaderName("X-XSRF-TOKEN");
          return repository;
      }
  }
  </code></pre>
  
  <p>Resource server config:</p>
  
  <pre><code>@Configuration
  @EnableResourceServer
  public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter{
  
      @Autowired
      private TokenStore tokenStore;
  
      @Override
      public void configure(ResourceServerSecurityConfigurer resources)
              throws Exception {
          resources.tokenStore(tokenStore);
      }
  
      @Override
      public void configure(HttpSecurity http) throws Exception {
          // @formatter:off
          http.antMatcher("/**").authorizeRequests().antMatchers("/api/**").permitAll();
          // @formatter:on
      }
  }
  </code></pre>