### Question:
UrlRewriteResponse extends GatewayResponseWrapper implements Params,
    ResponseStreamer { @Override public void streamResponse( InputStream input, OutputStream output ) throws IOException { MimeType mimeType = getMimeType(); UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig(rewriter.getConfig(), bodyFilterName, mimeType); if (filterContentConfig != null) { String asType = filterContentConfig.asType(); if ( asType != null && !StringUtils.isBlank(asType)) { mimeType = MimeTypes.create(asType, getCharacterEncoding()); } } UrlRewriteStreamFilter filter = UrlRewriteStreamFilterFactory.create(mimeType, null); final InputStream inStream; final OutputStream outStream; if( filter != null ) { boolean isGzip = false; final BufferedInputStream inBuffer = new BufferedInputStream(input, STREAM_BUFFER_SIZE); inBuffer.mark(2); byte [] signature = new byte[2]; int len = inBuffer.read(signature); if( len == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b ) { isGzip = true; } inBuffer.reset(); final InputStream unFilteredStream; if(isGzip) { unFilteredStream = new GzipCompressorInputStream(inBuffer, true); } else { unFilteredStream = inBuffer; } String charset = MimeTypes.getCharset( mimeType, StandardCharsets.UTF_8.name() ); inStream = filter.filter( unFilteredStream, charset, rewriter, this, UrlRewriter.Direction.OUT, filterContentConfig ); outStream = (isGzip) ? new GZIPOutputStream(output, STREAM_BUFFER_SIZE) : output; } else { inStream = input; outStream = output; } try { IOUtils.copy(inStream, outStream, STREAM_BUFFER_SIZE); } finally { outStream.close(); } } UrlRewriteResponse( FilterConfig config, HttpServletRequest request, HttpServletResponse response ); @Override void setHeader( String name, String value ); @Override void addHeader( String name, String value ); @Override OutputStream getRawOutputStream(); @Override void streamResponse( InputStream input, OutputStream output ); @Override ServletOutputStream getOutputStream(); @Override Set<String> getNames(); @Override @SuppressWarnings( "unchecked" ) List<String> resolve( String name ); @Override @SuppressWarnings("deprecation") String encodeUrl( String url ); @Override String encodeURL(String url ); @Override @SuppressWarnings("deprecation") String encodeRedirectUrl( String url ); @Override String encodeRedirectURL(String url ); static final String INBOUND_QUERY_PARAM_PREFIX; }### Answer:
@Test public void testStreamResponse() throws IOException { UrlRewriteProcessor rewriter = EasyMock.createNiceMock( UrlRewriteProcessor.class ); EasyMock.expect( rewriter.getConfig() ).andReturn( null ).anyTimes(); ServletContext context = EasyMock.createNiceMock( ServletContext.class ); EasyMock.expect( context.getAttribute( UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME ) ).andReturn( rewriter ).anyTimes(); FilterConfig config = EasyMock.createNiceMock( FilterConfig.class ); EasyMock.expect( config.getInitParameter( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM ) ).andReturn( "test-filter" ).anyTimes(); EasyMock.expect( config.getServletContext() ).andReturn( context ).anyTimes(); HttpServletRequest request = EasyMock.createNiceMock( HttpServletRequest.class ); HttpServletResponse response = EasyMock.createNiceMock( HttpServletResponse.class ); EasyMock.replay( rewriter, context, config, request, response ); UrlRewriteResponse rewriteResponse = new UrlRewriteResponse( config, request, response ); String content = "content to test gzip streaming"; testStreamResponse(content, rewriteResponse, false); testStreamResponse(content, rewriteResponse, true); }