@Test public void should_not_apply_if_the_response_has_an_incompatible_mimeType() { response.setContentType("incompatible-content-type"); HandlerContext handlerContext = new HandlerContext(context, request, response, null); assertThat(handler.isApplicable(handlerContext)).isFalse(); }
@Override public boolean isApplicable(HandlerContext handlerContext) { String mimeType = handlerContext.getResponse().getContentType(); boolean gzipEnabled = handlerContext.getContext().getConfiguration().isToolGzipEnabled(); boolean requestNotIncluded = !isIncluded(handlerContext.getRequest()); boolean browserAcceptsGzip = acceptsGzip(handlerContext.getRequest()); boolean responseNotCommited = !handlerContext.getResponse().isCommitted(); boolean compatibleMimeType = getSupportedMimeTypes(handlerContext.getContext()).contains(mimeType); LOG.trace( "gzipEnabled: {}, requestNotInclude: {}, browserAcceptsGzip: {}, responseNotCommited: {}, compatibleMimeType: {}", gzipEnabled, requestNotIncluded, browserAcceptsGzip, responseNotCommited, compatibleMimeType); return gzipEnabled && requestNotIncluded && browserAcceptsGzip && responseNotCommited && compatibleMimeType; }
GzipCompressionPostHandler extends AbstractHandlerChain { @Override public boolean isApplicable(HandlerContext handlerContext) { String mimeType = handlerContext.getResponse().getContentType(); boolean gzipEnabled = handlerContext.getContext().getConfiguration().isToolGzipEnabled(); boolean requestNotIncluded = !isIncluded(handlerContext.getRequest()); boolean browserAcceptsGzip = acceptsGzip(handlerContext.getRequest()); boolean responseNotCommited = !handlerContext.getResponse().isCommitted(); boolean compatibleMimeType = getSupportedMimeTypes(handlerContext.getContext()).contains(mimeType); LOG.trace( "gzipEnabled: {}, requestNotInclude: {}, browserAcceptsGzip: {}, responseNotCommited: {}, compatibleMimeType: {}", gzipEnabled, requestNotIncluded, browserAcceptsGzip, responseNotCommited, compatibleMimeType); return gzipEnabled && requestNotIncluded && browserAcceptsGzip && responseNotCommited && compatibleMimeType; } }
GzipCompressionPostHandler extends AbstractHandlerChain { @Override public boolean isApplicable(HandlerContext handlerContext) { String mimeType = handlerContext.getResponse().getContentType(); boolean gzipEnabled = handlerContext.getContext().getConfiguration().isToolGzipEnabled(); boolean requestNotIncluded = !isIncluded(handlerContext.getRequest()); boolean browserAcceptsGzip = acceptsGzip(handlerContext.getRequest()); boolean responseNotCommited = !handlerContext.getResponse().isCommitted(); boolean compatibleMimeType = getSupportedMimeTypes(handlerContext.getContext()).contains(mimeType); LOG.trace( "gzipEnabled: {}, requestNotInclude: {}, browserAcceptsGzip: {}, responseNotCommited: {}, compatibleMimeType: {}", gzipEnabled, requestNotIncluded, browserAcceptsGzip, responseNotCommited, compatibleMimeType); return gzipEnabled && requestNotIncluded && browserAcceptsGzip && responseNotCommited && compatibleMimeType; }  }
GzipCompressionPostHandler extends AbstractHandlerChain { @Override public boolean isApplicable(HandlerContext handlerContext) { String mimeType = handlerContext.getResponse().getContentType(); boolean gzipEnabled = handlerContext.getContext().getConfiguration().isToolGzipEnabled(); boolean requestNotIncluded = !isIncluded(handlerContext.getRequest()); boolean browserAcceptsGzip = acceptsGzip(handlerContext.getRequest()); boolean responseNotCommited = !handlerContext.getResponse().isCommitted(); boolean compatibleMimeType = getSupportedMimeTypes(handlerContext.getContext()).contains(mimeType); LOG.trace( "gzipEnabled: {}, requestNotInclude: {}, browserAcceptsGzip: {}, responseNotCommited: {}, compatibleMimeType: {}", gzipEnabled, requestNotIncluded, browserAcceptsGzip, responseNotCommited, compatibleMimeType); return gzipEnabled && requestNotIncluded && browserAcceptsGzip && responseNotCommited && compatibleMimeType; }  @Override boolean isAfterChaining(); @Override int getRank(); @Override boolean isApplicable(HandlerContext handlerContext); @Override boolean handle(HandlerContext handlerContext); Set<String> getSupportedMimeTypes(Context context); }
GzipCompressionPostHandler extends AbstractHandlerChain { @Override public boolean isApplicable(HandlerContext handlerContext) { String mimeType = handlerContext.getResponse().getContentType(); boolean gzipEnabled = handlerContext.getContext().getConfiguration().isToolGzipEnabled(); boolean requestNotIncluded = !isIncluded(handlerContext.getRequest()); boolean browserAcceptsGzip = acceptsGzip(handlerContext.getRequest()); boolean responseNotCommited = !handlerContext.getResponse().isCommitted(); boolean compatibleMimeType = getSupportedMimeTypes(handlerContext.getContext()).contains(mimeType); LOG.trace( "gzipEnabled: {}, requestNotInclude: {}, browserAcceptsGzip: {}, responseNotCommited: {}, compatibleMimeType: {}", gzipEnabled, requestNotIncluded, browserAcceptsGzip, responseNotCommited, compatibleMimeType); return gzipEnabled && requestNotIncluded && browserAcceptsGzip && responseNotCommited && compatibleMimeType; }  @Override boolean isAfterChaining(); @Override int getRank(); @Override boolean isApplicable(HandlerContext handlerContext); @Override boolean handle(HandlerContext handlerContext); Set<String> getSupportedMimeTypes(Context context);  }