public final class HttpConnection extends Object
Send request headers.
fixed-length or chunked.
Read response headers.
fixed-length, chunked
or unknown length.
Exchanges that do not have a request body may skip creating and closing
the request body. Exchanges that do not have a response body can call newFixedLengthSource(0) and may skip reading and
closing that source.
| Constructor and Description |
|---|
HttpConnection(ConnectionPool pool,
Connection connection,
Socket socket) |
| Modifier and Type | Method and Description |
|---|---|
long |
bufferSize()
Returns the number of buffered bytes immediately readable.
|
void |
closeIfOwnedBy(Object owner) |
void |
closeOnIdle()
Configure this connection to close itself when the HTTP response body is
exhausted.
|
void |
flush() |
boolean |
isClosed()
Returns true if this connection is closed.
|
boolean |
isReadable()
Test for a stale socket.
|
Sink |
newChunkedSink() |
Source |
newChunkedSource(HttpEngine httpEngine) |
Sink |
newFixedLengthSink(long contentLength) |
Source |
newFixedLengthSource(long length) |
Source |
newUnknownLengthSource() |
void |
poolOnIdle()
Configure this connection to put itself back into the connection pool when
the HTTP response body is exhausted.
|
BufferedSink |
rawSink() |
BufferedSource |
rawSource() |
void |
readHeaders(Headers.Builder builder)
Reads headers or trailers into
builder. |
Response.Builder |
readResponse()
Parses bytes of a response header from an HTTP transport.
|
void |
setTimeouts(int readTimeoutMillis,
int writeTimeoutMillis) |
void |
writeRequest(Headers headers,
String requestLine)
Returns bytes of a request header for sending on an HTTP transport.
|
void |
writeRequestBody(RetryableSink requestBody) |
public HttpConnection(ConnectionPool pool, Connection connection, Socket socket) throws IOException
IOExceptionpublic void setTimeouts(int readTimeoutMillis,
int writeTimeoutMillis)
public void poolOnIdle()
public void closeOnIdle()
throws IOException
IOExceptionpublic boolean isClosed()
public void closeIfOwnedBy(Object owner) throws IOException
IOExceptionpublic void flush()
throws IOException
IOExceptionpublic long bufferSize()
public boolean isReadable()
public void writeRequest(Headers headers, String requestLine) throws IOException
IOExceptionpublic Response.Builder readResponse() throws IOException
IOExceptionpublic void readHeaders(Headers.Builder builder) throws IOException
builder.IOExceptionpublic Sink newChunkedSink()
public Sink newFixedLengthSink(long contentLength)
public void writeRequestBody(RetryableSink requestBody) throws IOException
IOExceptionpublic Source newFixedLengthSource(long length) throws IOException
IOExceptionpublic Source newChunkedSource(HttpEngine httpEngine) throws IOException
IOExceptionpublic Source newUnknownLengthSource() throws IOException
IOExceptionpublic BufferedSink rawSink()
public BufferedSource rawSource()