Class HttpTransport
- java.lang.Object
-
- com.squareup.okhttp.internal.http.HttpTransport
-
-
Field Summary
-
Fields inherited from interface com.squareup.okhttp.internal.http.Transport
DISCARD_STREAM_TIMEOUT_MILLIS
-
-
Constructor Summary
Constructors Constructor Description HttpTransport(HttpEngine httpEngine, HttpConnection httpConnection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanReuseConnection()Returns true if the socket connection held by this transport can be reused for a follow-up exchange.SinkcreateRequestBody(Request request, long contentLength)Returns an output stream where the request body can be streamed.voiddisconnect(HttpEngine engine)voidfinishRequest()Flush the request to the underlying socket.ResponseBodyopenResponseBody(Response response)Returns a stream that reads the response body.Response.BuilderreadResponseHeaders()Read and return response headers.voidreleaseConnectionOnIdle()Configures the response body to pool or close the socket connection when the response body is closed.voidwriteRequestBody(RetryableSink requestBody)Sends the request body returned byTransport.createRequestBody(com.squareup.okhttp.Request, long)to the remote peer.voidwriteRequestHeaders(Request request)Prepares the HTTP headers and sends them to the server.
-
-
-
Constructor Detail
-
HttpTransport
public HttpTransport(HttpEngine httpEngine, HttpConnection httpConnection)
-
-
Method Detail
-
createRequestBody
public Sink createRequestBody(Request request, long contentLength) throws IOException
Description copied from interface:TransportReturns an output stream where the request body can be streamed.- Specified by:
createRequestBodyin interfaceTransport- Throws:
IOException
-
finishRequest
public void finishRequest() throws IOExceptionDescription copied from interface:TransportFlush the request to the underlying socket.- Specified by:
finishRequestin interfaceTransport- Throws:
IOException
-
writeRequestBody
public void writeRequestBody(RetryableSink requestBody) throws IOException
Description copied from interface:TransportSends the request body returned byTransport.createRequestBody(com.squareup.okhttp.Request, long)to the remote peer.- Specified by:
writeRequestBodyin interfaceTransport- Throws:
IOException
-
writeRequestHeaders
public void writeRequestHeaders(Request request) throws IOException
Prepares the HTTP headers and sends them to the server.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-Lengthheader field receives the proper value.- Specified by:
writeRequestHeadersin interfaceTransport- Throws:
IOException
-
readResponseHeaders
public Response.Builder readResponseHeaders() throws IOException
Description copied from interface:TransportRead and return response headers.- Specified by:
readResponseHeadersin interfaceTransport- Throws:
IOException
-
releaseConnectionOnIdle
public void releaseConnectionOnIdle() throws IOExceptionDescription copied from interface:TransportConfigures the response body to pool or close the socket connection when the response body is closed.- Specified by:
releaseConnectionOnIdlein interfaceTransport- Throws:
IOException
-
canReuseConnection
public boolean canReuseConnection()
Description copied from interface:TransportReturns true if the socket connection held by this transport can be reused for a follow-up exchange.- Specified by:
canReuseConnectionin interfaceTransport
-
openResponseBody
public ResponseBody openResponseBody(Response response) throws IOException
Description copied from interface:TransportReturns a stream that reads the response body.- Specified by:
openResponseBodyin interfaceTransport- Throws:
IOException
-
disconnect
public void disconnect(HttpEngine engine) throws IOException
- Specified by:
disconnectin interfaceTransport- Throws:
IOException
-
-