public final class Http1xStream extends Object implements HttpStream
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.
DISCARD_STREAM_TIMEOUT_MILLIS
Constructor and Description |
---|
Http1xStream(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.
|
boolean |
isClosed()
Returns true if this connection is closed.
|
okio.Sink |
newChunkedSink() |
okio.Source |
newChunkedSource(HttpEngine httpEngine) |
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 |
readResponse()
Parses bytes of a response header from an HTTP transport.
|
Response.Builder |
readResponseHeaders()
Read and return response headers.
|
void |
setHttpEngine(HttpEngine httpEngine) |
void |
writeRequest(Headers headers,
String requestLine)
Returns bytes of a request header for sending on an HTTP transport.
|
void |
writeRequestBody(RetryableSink requestBody)
Sends the request body returned by
HttpStream.createRequestBody(com.squareup.okhttp.Request, long) to the
remote peer. |
void |
writeRequestHeaders(Request request)
Prepares the HTTP headers and sends them to the server.
|
public Http1xStream(StreamAllocation streamAllocation, okio.BufferedSource source, okio.BufferedSink sink)
public void setHttpEngine(HttpEngine httpEngine)
setHttpEngine
in interface HttpStream
public okio.Sink createRequestBody(Request request, long contentLength) throws IOException
HttpStream
createRequestBody
in interface HttpStream
IOException
public void cancel()
HttpStream
cancel
in interface HttpStream
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 HttpStream
IOException
public Response.Builder readResponseHeaders() throws IOException
HttpStream
readResponseHeaders
in interface HttpStream
IOException
public ResponseBody openResponseBody(Response response) throws IOException
HttpStream
openResponseBody
in interface HttpStream
IOException
public boolean isClosed()
public void finishRequest() throws IOException
HttpStream
finishRequest
in interface HttpStream
IOException
public void writeRequest(Headers headers, String requestLine) throws IOException
IOException
public Response.Builder readResponse() throws IOException
IOException
public Headers readHeaders() throws IOException
IOException
public okio.Sink newChunkedSink()
public okio.Sink newFixedLengthSink(long contentLength)
public void writeRequestBody(RetryableSink requestBody) throws IOException
HttpStream
HttpStream.createRequestBody(com.squareup.okhttp.Request, long)
to the
remote peer.writeRequestBody
in interface HttpStream
IOException
public okio.Source newFixedLengthSource(long length) throws IOException
IOException
public okio.Source newChunkedSource(HttpEngine httpEngine) throws IOException
IOException
public okio.Source newUnknownLengthSource() throws IOException
IOException
Copyright © 2017. All rights reserved.