SuppressGzipCompression implements ResponseFormatter { @Override public byte[] formatResponse(WilmaHttpRequest wilmaRequest, HttpServletResponse resp, byte[] responseResource, ParameterList params) { String acceptEncodingHeader = wilmaRequest.getHeader(HEADER_KEY_ACCEPT_ENCODING); if (acceptEncodingHeader != null && acceptEncodingHeader.contains(HEADER_VALUE_GZIP)) { String existingHeaderContent = resp.getHeader(HEADER_KEY_SUPPRESS_ENCODING); String newHeaderContent = existingHeaderContent == null ? HEADER_VALUE_GZIP : existingHeaderContent + "," + HEADER_VALUE_GZIP; resp.addHeader(HEADER_KEY_SUPPRESS_ENCODING, newHeaderContent); } return responseResource; }  @Override byte[] formatResponse(WilmaHttpRequest wilmaRequest, HttpServletResponse resp, byte[] responseResource, ParameterList params);  }
@Test public void testFormatTemplateWithoutExistingHeader() { given(request.getHeader(SuppressGzipCompression.HEADER_KEY_ACCEPT_ENCODING)).willReturn(SuppressGzipCompression.HEADER_VALUE_GZIP); given(response.getHeader(SuppressGzipCompression.HEADER_KEY_SUPPRESS_ENCODING)).willReturn(null); underTest.formatResponse(request, response, null, parameterMap); verify(response).addHeader(SuppressGzipCompression.HEADER_KEY_SUPPRESS_ENCODING, SuppressGzipCompression.HEADER_VALUE_GZIP); }
@Test public void testFormatTemplateWithExistingHeader() { given(request.getHeader(SuppressGzipCompression.HEADER_KEY_ACCEPT_ENCODING)).willReturn(SuppressGzipCompression.HEADER_VALUE_GZIP); given(response.getHeader(SuppressGzipCompression.HEADER_KEY_SUPPRESS_ENCODING)).willReturn(ANY_HEADER_VALUE); underTest.formatResponse(request, response, null, parameterMap); verify(response).addHeader(SuppressGzipCompression.HEADER_KEY_SUPPRESS_ENCODING, ANY_HEADER_VALUE + "," + SuppressGzipCompression.HEADER_VALUE_GZIP); }