All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Enclosing class:
I2PTunnelHTTPServer

private static class I2PTunnelHTTPServer.CompressedResponseOutputStreamextends HTTPResponseOutputStream
Gzips the response on its way to the browser.
  • Field Details

    • _gzipOut

      private GZIPOutputStream _gzipOut
      The gzip stream for the response.
    • _requestHeaders

      private final String _requestHeaders
      Request headers used to judge compression.
    • COMPRESSED_TYPES

      private static final Set<String> COMPRESSED_TYPES
      Content types that are already compressed; skip re-compression.
  • Constructor Details

    • CompressedResponseOutputStream

      public CompressedResponseOutputStream(OutputStream o, boolean keepalive, String requestHeaders)
      Create a compressed response output stream.
      Parameters:
      o - the underlying output stream
      keepalive - if true, don't close the stream on finish
      requestHeaders - the HTTP request headers for Accept-Encoding check
  • Method Details

    • finish

      public void finish() throws IOException
      Finish gzipping but don't close the output stream if keepalive is true. Overridden to peek at response code. Always returns line.
      Throws:
      IOException - if finishing the gzip stream fails
    • shouldCompress

      protected boolean shouldCompress()
      Determine if the response should be gzip-compressed. Skips small responses, images, audio, video, and already-compressed formats. Compression is inline on the server side, decompression on the client side, so we avoid re-compressing formats that are already compressed.
      Overrides:
      shouldCompress in class HTTPResponseOutputStream
      Returns:
      true if the response should be compressed
    • finishHeaders

      protected void finishHeaders() throws IOException
      Write the Content-Encoding header if compression is enabled.
      Overrides:
      finishHeaders in class HTTPResponseOutputStream
      Throws:
      IOException - if writing the header fails
    • beginProcessing

      protected void beginProcessing() throws IOException
      Wrap the output stream with gzip compression if compression is enabled.
      Overrides:
      beginProcessing in class HTTPResponseOutputStream
      Throws:
      IOException - if creating the gzip stream fails