public final class Http1Codec extends 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.
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.
|
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.
|
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,
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.
|
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 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
IOException
public ResponseBody openResponseBody(Response response) throws IOException
HttpCodec
openResponseBody
in interface HttpCodec
IOException
public boolean isClosed()
public void flushRequest() throws IOException
HttpCodec
flushRequest
in interface HttpCodec
IOException
public void finishRequest() throws IOException
HttpCodec
finishRequest
in interface HttpCodec
IOException
public void writeRequest(Headers headers, String requestLine) throws IOException
IOException
public Response.Builder readResponseHeaders(boolean expectContinue) throws 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.IOException
public Headers readHeaders() throws IOException
IOException
public okio.Sink newChunkedSink()
public okio.Sink newFixedLengthSink(long contentLength)
public okio.Source newFixedLengthSource(long length) throws IOException
IOException
public okio.Source newChunkedSource(HttpUrl url) throws IOException
IOException
public okio.Source newUnknownLengthSource() throws IOException
IOException
Copyright © 2019. All rights reserved.