Class HTTPResponseOutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
net.i2p.i2ptunnel.HTTPResponseOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

class HTTPResponseOutputStream extends FilterOutputStream
This does the transparent gzip decompression on the client side. Extended in I2PTunnelHTTPServer to do the compression on the server side. Simple stream for delivering an HTTP response to the client, trivially filtered to make sure "Connection: close" is always in the response. Perhaps add transparent handling of the Content-Encoding: x-i2p-gzip, adjusting the headers to say Content-Encoding: identity? Content-Encoding: gzip is trivial as well, but Transfer-Encoding: chunked makes it more work than is worthwhile at the moment.
  • Field Details

    • _headerBuffer

      protected ByteArray _headerBuffer
    • _gzip

      protected boolean _gzip
    • _dataExpected

      protected long _dataExpected
    • _keepAliveIn

      protected boolean _keepAliveIn
    • _keepAliveOut

      protected boolean _keepAliveOut
    • _contentType

      protected String _contentType
      lower-case, trimmed
    • _contentEncoding

      protected String _contentEncoding
      lower-case, trimmed
  • Constructor Details

    • HTTPResponseOutputStream

      public HTTPResponseOutputStream(OutputStream raw)
    • HTTPResponseOutputStream

      public HTTPResponseOutputStream(OutputStream raw, boolean allowKeepAliveIn, boolean allowKeepAliveOut, boolean isHead, LimitOutputStream.DoneCallback cb)
      Optionally keep sockets alive and call callback when we're done.
      Parameters:
      allowKeepAliveIn - We may, but are not required to, keep the input socket alive. This is the server on the server side and I2P on the client side.
      allowKeepAliveOut - We may, but are not required to, keep the output socket alive. This is I2P on the server side and the browser on the client side.
      isHead - is this a response to a HEAD, and thus no data is expected (RFC 2616 sec. 4.4)
      cb - non-null if allowKeepAlive is true
      Since:
      0.9.62
  • Method Details

    • getKeepAliveIn

      public boolean getKeepAliveIn()
      Should we keep the input stream alive when done?
      Returns:
      false before the headers are written
      Since:
      0.9.62
    • getKeepAliveOut

      public boolean getKeepAliveOut()
      Should we keep the output stream alive when done? Only supported for the browser socket side. I2P socket on server side not supported yet.
      Returns:
      false before the headers are written
      Since:
      0.9.62
    • write

      public void write(int c) throws IOException
      Overrides:
      write in class FilterOutputStream
      Throws:
      IOException
    • write

      public void write(byte[] buf, int off, int len) throws IOException
      Overrides:
      write in class FilterOutputStream
      Throws:
      IOException
    • filterResponseLine

      protected String filterResponseLine(String line)
      Possibly tweak that first HTTP response line (HTTP/1.0 200 OK, etc). Overridden on server side.
    • shouldCompress

      protected boolean shouldCompress()
    • finishHeaders

      protected void finishHeaders() throws IOException
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterOutputStream
      Throws:
      IOException
    • beginProcessing

      protected void beginProcessing() throws IOException
      Throws:
      IOException