@Test public void should_return_false_if_304() throws Exception { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); HandlerContext handlerContext = new HandlerContext(context, request, response, "".getBytes()); assertThat(handler.handle(handlerContext)).isFalse(); }
@Override public boolean handle(HandlerContext handlerContext) { byte[] compressedContent = getGzippedContent(handlerContext.getResponseAsBytes()); if (handlerContext.getResponse().isCommitted()) { return false; } switch (handlerContext.getResponse().getStatus()) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_RESET_CONTENT: case HttpServletResponse.SC_NOT_MODIFIED: return false; default: } boolean shouldGzippedBodyBeZero = shouldGzippedBodyBeZero(compressedContent, handlerContext.getRequest()); boolean shouldBodyBeZero = shouldBodyBeZero(handlerContext.getRequest(), handlerContext.getResponse().getStatus()); if (shouldGzippedBodyBeZero || shouldBodyBeZero) { handlerContext.getResponse().setContentLength(0); return false; } handlerContext.getResponse().setContentLength(compressedContent.length); addGzipHeader(handlerContext.getResponse()); handlerContext.setResponseAsBytes(compressedContent); return true; }
GzipCompressionPostHandler extends AbstractHandlerChain { @Override public boolean handle(HandlerContext handlerContext) { byte[] compressedContent = getGzippedContent(handlerContext.getResponseAsBytes()); if (handlerContext.getResponse().isCommitted()) { return false; } switch (handlerContext.getResponse().getStatus()) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_RESET_CONTENT: case HttpServletResponse.SC_NOT_MODIFIED: return false; default: } boolean shouldGzippedBodyBeZero = shouldGzippedBodyBeZero(compressedContent, handlerContext.getRequest()); boolean shouldBodyBeZero = shouldBodyBeZero(handlerContext.getRequest(), handlerContext.getResponse().getStatus()); if (shouldGzippedBodyBeZero || shouldBodyBeZero) { handlerContext.getResponse().setContentLength(0); return false; } handlerContext.getResponse().setContentLength(compressedContent.length); addGzipHeader(handlerContext.getResponse()); handlerContext.setResponseAsBytes(compressedContent); return true; } }
GzipCompressionPostHandler extends AbstractHandlerChain { @Override public boolean handle(HandlerContext handlerContext) { byte[] compressedContent = getGzippedContent(handlerContext.getResponseAsBytes()); if (handlerContext.getResponse().isCommitted()) { return false; } switch (handlerContext.getResponse().getStatus()) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_RESET_CONTENT: case HttpServletResponse.SC_NOT_MODIFIED: return false; default: } boolean shouldGzippedBodyBeZero = shouldGzippedBodyBeZero(compressedContent, handlerContext.getRequest()); boolean shouldBodyBeZero = shouldBodyBeZero(handlerContext.getRequest(), handlerContext.getResponse().getStatus()); if (shouldGzippedBodyBeZero || shouldBodyBeZero) { handlerContext.getResponse().setContentLength(0); return false; } handlerContext.getResponse().setContentLength(compressedContent.length); addGzipHeader(handlerContext.getResponse()); handlerContext.setResponseAsBytes(compressedContent); return true; }  }
GzipCompressionPostHandler extends AbstractHandlerChain { @Override public boolean handle(HandlerContext handlerContext) { byte[] compressedContent = getGzippedContent(handlerContext.getResponseAsBytes()); if (handlerContext.getResponse().isCommitted()) { return false; } switch (handlerContext.getResponse().getStatus()) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_RESET_CONTENT: case HttpServletResponse.SC_NOT_MODIFIED: return false; default: } boolean shouldGzippedBodyBeZero = shouldGzippedBodyBeZero(compressedContent, handlerContext.getRequest()); boolean shouldBodyBeZero = shouldBodyBeZero(handlerContext.getRequest(), handlerContext.getResponse().getStatus()); if (shouldGzippedBodyBeZero || shouldBodyBeZero) { handlerContext.getResponse().setContentLength(0); return false; } handlerContext.getResponse().setContentLength(compressedContent.length); addGzipHeader(handlerContext.getResponse()); handlerContext.setResponseAsBytes(compressedContent); return true; }  @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 handle(HandlerContext handlerContext) { byte[] compressedContent = getGzippedContent(handlerContext.getResponseAsBytes()); if (handlerContext.getResponse().isCommitted()) { return false; } switch (handlerContext.getResponse().getStatus()) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_RESET_CONTENT: case HttpServletResponse.SC_NOT_MODIFIED: return false; default: } boolean shouldGzippedBodyBeZero = shouldGzippedBodyBeZero(compressedContent, handlerContext.getRequest()); boolean shouldBodyBeZero = shouldBodyBeZero(handlerContext.getRequest(), handlerContext.getResponse().getStatus()); if (shouldGzippedBodyBeZero || shouldBodyBeZero) { handlerContext.getResponse().setContentLength(0); return false; } handlerContext.getResponse().setContentLength(compressedContent.length); addGzipHeader(handlerContext.getResponse()); handlerContext.setResponseAsBytes(compressedContent); return true; }  @Override boolean isAfterChaining(); @Override int getRank(); @Override boolean isApplicable(HandlerContext handlerContext); @Override boolean handle(HandlerContext handlerContext); Set<String> getSupportedMimeTypes(Context context);  }