public final class Http1ExchangeCodec extends java.lang.Object implements ExchangeCodec
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 |
Http1ExchangeCodec.AbstractSource |
private class |
Http1ExchangeCodec.ChunkedSink
An HTTP body with alternating chunk sizes and chunk bodies.
|
private class |
Http1ExchangeCodec.ChunkedSource
An HTTP body with alternating chunk sizes and chunk bodies.
|
private class |
Http1ExchangeCodec.FixedLengthSource
An HTTP body with a fixed length specified in advance.
|
private class |
Http1ExchangeCodec.KnownLengthSink
An HTTP request body.
|
private class |
Http1ExchangeCodec.UnknownLengthSource
An HTTP message body terminated by the end of the underlying stream.
|
Modifier and Type | Field and Description |
---|---|
private OkHttpClient |
client
The client that configures this stream.
|
private static int |
HEADER_LIMIT |
private long |
headerLimit |
private RealConnection |
realConnection
The connection that carries this stream.
|
private okio.BufferedSink |
sink |
private okio.BufferedSource |
source |
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 |
private Headers |
trailers
Received trailers.
|
DISCARD_STREAM_TIMEOUT_MILLIS
Constructor and Description |
---|
Http1ExchangeCodec(OkHttpClient client,
RealConnection realConnection,
okio.BufferedSource source,
okio.BufferedSink sink) |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancel this stream.
|
RealConnection |
connection()
Returns the connection that carries this codec.
|
okio.Sink |
createRequestBody(Request request,
long contentLength)
Returns an output stream where the request body can be streamed.
|
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.
|
private okio.Sink |
newChunkedSink() |
private okio.Source |
newChunkedSource(HttpUrl url) |
private okio.Source |
newFixedLengthSource(long length) |
private okio.Sink |
newKnownLengthSink() |
private okio.Source |
newUnknownLengthSource() |
okio.Source |
openResponseBodySource(Response response) |
private java.lang.String |
readHeaderLine() |
private Headers |
readHeaders()
Reads headers or trailers.
|
Response.Builder |
readResponseHeaders(boolean expectContinue)
Parses bytes of a response header from an HTTP transport.
|
long |
reportedContentLength(Response response) |
void |
skipConnectBody(Response response)
The response body from a CONNECT should be empty, but if it is not then we should consume it
before proceeding.
|
Headers |
trailers()
Returns the trailers after the HTTP response.
|
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
private final OkHttpClient client
private final RealConnection realConnection
private final okio.BufferedSource source
private final okio.BufferedSink sink
private int state
private long headerLimit
private Headers trailers
public Http1ExchangeCodec(OkHttpClient client, RealConnection realConnection, okio.BufferedSource source, okio.BufferedSink sink)
public RealConnection connection()
ExchangeCodec
connection
in interface ExchangeCodec
public okio.Sink createRequestBody(Request request, long contentLength) throws java.io.IOException
ExchangeCodec
createRequestBody
in interface ExchangeCodec
java.io.IOException
public void cancel()
ExchangeCodec
cancel
in interface ExchangeCodec
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 ExchangeCodec
java.io.IOException
public long reportedContentLength(Response response)
reportedContentLength
in interface ExchangeCodec
public okio.Source openResponseBodySource(Response response)
openResponseBodySource
in interface ExchangeCodec
public Headers trailers()
ExchangeCodec
trailers
in interface ExchangeCodec
public boolean isClosed()
public void flushRequest() throws java.io.IOException
ExchangeCodec
flushRequest
in interface ExchangeCodec
java.io.IOException
public void finishRequest() throws java.io.IOException
ExchangeCodec
finishRequest
in interface ExchangeCodec
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
ExchangeCodec
readResponseHeaders
in interface ExchangeCodec
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
private Headers readHeaders() throws java.io.IOException
java.io.IOException
private okio.Sink newChunkedSink()
private okio.Sink newKnownLengthSink()
private okio.Source newFixedLengthSource(long length)
private okio.Source newChunkedSource(HttpUrl url)
private okio.Source newUnknownLengthSource()
private 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.public void skipConnectBody(Response response) throws java.io.IOException
java.io.IOException