public final class Http1ExchangeCodec extends 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.
DISCARD_STREAM_TIMEOUT_MILLIS| 构造器和说明 |
|---|
Http1ExchangeCodec(OkHttpClient client,
RealConnection realConnection,
BufferedSource source,
BufferedSink sink) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
cancel()
Cancel this stream.
|
RealConnection |
connection()
Returns the connection that carries this codec.
|
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.
|
Source |
openResponseBodySource(Response response) |
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,
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 Http1ExchangeCodec(OkHttpClient client, RealConnection realConnection, BufferedSource source, BufferedSink sink)
public RealConnection connection()
ExchangeCodecconnection 在接口中 ExchangeCodecpublic Sink createRequestBody(Request request, long contentLength) throws IOException
ExchangeCodeccreateRequestBody 在接口中 ExchangeCodecIOExceptionpublic void cancel()
ExchangeCodeccancel 在接口中 ExchangeCodecpublic 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 在接口中 ExchangeCodecIOExceptionpublic long reportedContentLength(Response response)
reportedContentLength 在接口中 ExchangeCodecpublic Source openResponseBodySource(Response response)
openResponseBodySource 在接口中 ExchangeCodecpublic Headers trailers()
ExchangeCodectrailers 在接口中 ExchangeCodecpublic boolean isClosed()
public void flushRequest()
throws IOException
ExchangeCodecflushRequest 在接口中 ExchangeCodecIOExceptionpublic void finishRequest()
throws IOException
ExchangeCodecfinishRequest 在接口中 ExchangeCodecIOExceptionpublic void writeRequest(Headers headers, String requestLine) throws IOException
IOExceptionpublic Response.Builder readResponseHeaders(boolean expectContinue) throws IOException
ExchangeCodecreadResponseHeaders 在接口中 ExchangeCodecexpectContinue - true to return null if this is an intermediate response with a "100"
response code. Otherwise this method never returns null.IOExceptionpublic void skipConnectBody(Response response) throws IOException
IOExceptionCopyright © 2025. All rights reserved.