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)
HttpCodeccreateRequestBody in interface HttpCodecpublic void cancel()
HttpCodecpublic 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 HttpCodecIOExceptionpublic ResponseBody openResponseBody(Response response) throws IOException
HttpCodecopenResponseBody in interface HttpCodecIOExceptionpublic boolean isClosed()
public void flushRequest()
throws IOException
HttpCodecflushRequest in interface HttpCodecIOExceptionpublic void finishRequest()
throws IOException
HttpCodecfinishRequest in interface HttpCodecIOExceptionpublic void writeRequest(Headers headers, String requestLine) throws IOException
IOExceptionpublic Response.Builder readResponseHeaders(boolean expectContinue) throws IOException
HttpCodecreadResponseHeaders in interface HttpCodecexpectContinue - true to return null if this is an intermediate response with a "100"
response code. Otherwise this method never returns null.IOExceptionpublic Headers readHeaders() throws IOException
IOExceptionpublic okio.Sink newChunkedSink()
public okio.Sink newFixedLengthSink(long contentLength)
public okio.Source newFixedLengthSource(long length)
throws IOException
IOExceptionpublic okio.Source newChunkedSource(HttpUrl url) throws IOException
IOExceptionpublic okio.Source newUnknownLengthSource()
throws IOException
IOExceptionCopyright © 2017. All Rights Reserved.