You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by "Larry McCay (Jira)" <ji...@apache.org> on 2021/06/18 00:06:00 UTC

[jira] [Commented] (KNOX-2622) Support Deflate Encoding for the Inbound Response

    [ https://issues.apache.org/jira/browse/KNOX-2622?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17365183#comment-17365183 ] 

Larry McCay commented on KNOX-2622:
-----------------------------------

Hi [~xuzikun2003] - thank you for the Jira and insights into what you would like here.
Are you planning to provide a pull request for this via github?

thanks!

> Support Deflate Encoding for the Inbound Response
> -------------------------------------------------
>
>                 Key: KNOX-2622
>                 URL: https://issues.apache.org/jira/browse/KNOX-2622
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: Server
>    Affects Versions: 1.4.0
>            Reporter: Zikun
>            Priority: Major
>             Fix For: 1.5.0
>
>
> 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)