Uploaded image for project: 'Apache Knox'
  1. Apache Knox
  2. KNOX-2622

Support Deflate Encoding for the Inbound Response

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.0
    • Fix Version/s: 1.6.0
    • Component/s: Server
    • Labels:
      None

      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

            Activity

              People

              • Assignee:
                xuzikun2003 Zikun
                Reporter:
                xuzikun2003 Zikun
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m