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
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
FieldsModifier and TypeFieldDescriptionprotected Stringlower-case, trimmedprotected Stringlower-case, trimmedprotected longprotected booleanprotected ByteArrayprotected booleanprotected booleanFields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionHTTPResponseOutputStream(OutputStream raw, boolean allowKeepAliveIn, boolean allowKeepAliveOut, boolean isHead, LimitOutputStream.DoneCallback cb) Optionally keep sockets alive and call callback when we're done. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()protected StringfilterResponseLine(String line) Possibly tweak that first HTTP response line (HTTP/1.0 200 OK, etc).protected voidbooleanShould we keep the input stream alive when done?booleanShould we keep the output stream alive when done? Only supported for the browser socket side.protected booleanvoidwrite(byte[] buf, int off, int len) voidwrite(int c) Methods inherited from class java.io.FilterOutputStream
flush, writeMethods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
_headerBuffer
-
_gzip
protected boolean _gzip -
_dataExpected
protected long _dataExpected -
_keepAliveIn
protected boolean _keepAliveIn -
_keepAliveOut
protected boolean _keepAliveOut -
_contentType
lower-case, trimmed -
_contentEncoding
lower-case, trimmed
-
-
Constructor Details
-
HTTPResponseOutputStream
-
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
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
filterResponseLine
Possibly tweak that first HTTP response line (HTTP/1.0 200 OK, etc). Overridden on server side. -
shouldCompress
protected boolean shouldCompress() -
finishHeaders
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
beginProcessing
- Throws:
IOException
-