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
Modifier and TypeFieldDescriptionprotected String
lower-case, trimmedprotected String
lower-case, trimmedprotected long
protected boolean
protected ByteArray
protected boolean
protected boolean
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorDescriptionHTTPResponseOutputStream
(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 void
void
close()
protected String
filterResponseLine
(String line) Possibly tweak that first HTTP response line (HTTP/1.0 200 OK, etc).protected void
boolean
Should we keep the input stream alive when done?boolean
Should we keep the output stream alive when done? Only supported for the browser socket side.protected boolean
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 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:
write
in classFilterOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
-
beginProcessing
- Throws:
IOException
-