public final class Http1Codec extends java.lang.Object implements HttpCodec
chunked
.
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.
Modifier and Type | Class and Description |
---|---|
private class |
Http1Codec.AbstractSource |
private class |
Http1Codec.ChunkedSink
An HTTP body with alternating chunk sizes and chunk bodies.
|
private class |
Http1Codec.ChunkedSource
An HTTP body with alternating chunk sizes and chunk bodies.
|
private class |
Http1Codec.FixedLengthSink
An HTTP body with a fixed length known in advance.
|
private class |
Http1Codec.FixedLengthSource
An HTTP body with a fixed length specified in advance.
|
private class |
Http1Codec.UnknownLengthSource
An HTTP message body terminated by the end of the underlying stream.
|
Modifier and Type | Field and Description |
---|---|
(package private) OkHttpClient |
client
The client that configures this stream.
|
private static int |
HEADER_LIMIT |
private long |
headerLimit |
(package private) okio.BufferedSink |
sink |
(package private) okio.BufferedSource |
source |
(package private) int |
state |
private static int |
STATE_CLOSED |
private static int |
STATE_IDLE |
private static int |
STATE_OPEN_REQUEST_BODY |
private static int |
STATE_OPEN_RESPONSE_BODY |
private static int |
STATE_READ_RESPONSE_HEADERS |
private static int |
STATE_READING_RESPONSE_BODY |
private static int |
STATE_WRITING_REQUEST_BODY |
(package private) StreamAllocation |
streamAllocation
The stream allocation that owns this stream.
|
DISCARD_STREAM_TIMEOUT_MILLIS
Constructor and Description |
---|
Http1Codec(OkHttpClient client,
StreamAllocation streamAllocation,
okio.BufferedSource source,
okio.BufferedSink sink) |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancel this stream.
|
okio.Sink |
createRequestBody(Request request,
long contentLength)
Returns an output stream where the request body can be streamed.
|
(package private) void |
detachTimeout(okio.ForwardingTimeout timeout)
Sets the delegate of
timeout to Timeout.NONE and resets its underlying timeout
to the default configuration. |
void |
finishRequest()
Flush the request to the underlying socket and signal no more bytes will be transmitted.
|
void |
flushRequest()
Flush the request to the underlying socket.
|
boolean |
isClosed()
Returns true if this connection is closed.
|
okio.Sink |
newChunkedSink() |
okio.Source |
newChunkedSource(HttpUrl url) |
okio.Sink |
newFixedLengthSink(long contentLength) |
okio.Source |
newFixedLengthSource(long length) |
okio.Source |
newUnknownLengthSource() |
ResponseBody |
openResponseBody(Response response)
Returns a stream that reads the response body.
|
private java.lang.String |
readHeaderLine() |
Headers |
readHeaders()
Reads headers or trailers.
|
Response.Builder |
readResponseHeaders(boolean expectContinue)
Parses bytes of a response header from an HTTP transport.
|
void |
writeRequest(Headers headers,
java.lang.String requestLine)
Returns bytes of a request header for sending on an HTTP transport.
|
void |
writeRequestHeaders(Request request)
Prepares the HTTP headers and sends them to the server.
|
private static final int STATE_IDLE
private static final int STATE_OPEN_REQUEST_BODY
private static final int STATE_WRITING_REQUEST_BODY
private static final int STATE_READ_RESPONSE_HEADERS
private static final int STATE_OPEN_RESPONSE_BODY
private static final int STATE_READING_RESPONSE_BODY
private static final int STATE_CLOSED
private static final int HEADER_LIMIT
final OkHttpClient client
final StreamAllocation streamAllocation
final okio.BufferedSource source
final okio.BufferedSink sink
int state
private long headerLimit
public Http1Codec(OkHttpClient client, StreamAllocation streamAllocation, okio.BufferedSource source, okio.BufferedSink sink)
public okio.Sink createRequestBody(Request request, long contentLength)
HttpCodec
createRequestBody
in interface HttpCodec
public void cancel()
HttpCodec
public void writeRequestHeaders(Request request) throws java.io.IOException
For streaming requests with a body, headers must be prepared before the output stream has been written to. Otherwise the body would need to be buffered!
For non-streaming requests with a body, headers must be prepared after the
output stream has been written to and closed. This ensures that the Content-Length
header field receives the proper value.
writeRequestHeaders
in interface HttpCodec
java.io.IOException
public ResponseBody openResponseBody(Response response) throws java.io.IOException
HttpCodec
openResponseBody
in interface HttpCodec
java.io.IOException
public boolean isClosed()
public void flushRequest() throws java.io.IOException
HttpCodec
flushRequest
in interface HttpCodec
java.io.IOException
public void finishRequest() throws java.io.IOException
HttpCodec
finishRequest
in interface HttpCodec
java.io.IOException
public void writeRequest(Headers headers, java.lang.String requestLine) throws java.io.IOException
java.io.IOException
public Response.Builder readResponseHeaders(boolean expectContinue) throws java.io.IOException
HttpCodec
readResponseHeaders
in interface HttpCodec
expectContinue
- true to return null if this is an intermediate response with a "100"
response code. Otherwise this method never returns null.java.io.IOException
private java.lang.String readHeaderLine() throws java.io.IOException
java.io.IOException
public Headers readHeaders() throws java.io.IOException
java.io.IOException
public okio.Sink newChunkedSink()
public okio.Sink newFixedLengthSink(long contentLength)
public okio.Source newFixedLengthSource(long length) throws java.io.IOException
java.io.IOException
public okio.Source newChunkedSource(HttpUrl url) throws java.io.IOException
java.io.IOException
public okio.Source newUnknownLengthSource() throws java.io.IOException
java.io.IOException
void detachTimeout(okio.ForwardingTimeout timeout)
timeout
to Timeout.NONE
and resets its underlying timeout
to the default configuration. Use this to avoid unexpected sharing of timeouts between pooled
connections.