Package net.i2p.i2ptunnel
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 Summary
Fields Modifier and Type Field Description protected String
_contentEncoding
lower-case, trimmedprotected String
_contentType
lower-case, trimmedprotected long
_dataExpected
protected boolean
_gzip
protected ByteArray
_headerBuffer
protected boolean
_keepAliveIn
protected boolean
_keepAliveOut
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description HTTPResponseOutputStream(OutputStream raw)
HTTPResponseOutputStream(OutputStream raw, boolean allowKeepAliveIn, boolean allowKeepAliveOut, boolean isHead, LimitOutputStream.DoneCallback cb)
Optionally keep sockets alive and call callback when we're done.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
beginProcessing()
void
close()
protected String
filterResponseLine(String line)
Possibly tweak that first HTTP response line (HTTP/1.0 200 OK, etc).protected void
finishHeaders()
boolean
getKeepAliveIn()
Should we keep the input stream alive when done?boolean
getKeepAliveOut()
Should we keep the output stream alive when done? Only supported for the browser socket side.protected boolean
shouldCompress()
void
write(byte[] buf, int off, int len)
void
write(int c)
-
Methods inherited from class java.io.FilterOutputStream
flush, write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Field Detail
-
_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 Detail
-
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 Detail
-
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 classFilterOutputStream
- Throws:
IOException
-
write
public void write(byte[] buf, int off, int len) throws IOException
- Overrides:
write
in classFilterOutputStream
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
-
beginProcessing
protected void beginProcessing() throws IOException
- Throws:
IOException
-
-