Description
Currently, Knox only supports the Content-Encoding "gzip" and the Content-Encoding "deflate" is not supported. When the upstream server (such as Livy 0.7 Server) returns a response which is deflated, Knox does not know how to decode it.
This is the part of logic that needs to be improved.
final InputStream inStream;
final OutputStream outStream;
if( filter != null )
{ // Use this way to check whether the input stream is gzip compressed, in case // the content encoding header is unknown, as it could be unset in inbound response 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; }
The above code only considers the "gzip" format and the "deflate" format is not considered. We should also handle the case when the format is "deflate" and use InflaterInputStream to read the in-bound response and use DeflaterOutputStream to write the out-bound response.
Attachments
Issue Links
- links to