Home | History | Annotate | Download | only in http
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.squareup.okhttp.internal.http;
     18 
     19 import com.squareup.okhttp.Request;
     20 import com.squareup.okhttp.Response;
     21 import com.squareup.okhttp.ResponseBody;
     22 import java.io.IOException;
     23 import okio.Sink;
     24 
     25 public interface Transport {
     26   /**
     27    * The timeout to use while discarding a stream of input data. Since this is
     28    * used for connection reuse, this timeout should be significantly less than
     29    * the time it takes to establish a new connection.
     30    */
     31   int DISCARD_STREAM_TIMEOUT_MILLIS = 100;
     32 
     33   /** Returns an output stream where the request body can be streamed. */
     34   Sink createRequestBody(Request request, long contentLength) throws IOException;
     35 
     36   /** This should update the HTTP engine's sentRequestMillis field. */
     37   void writeRequestHeaders(Request request) throws IOException;
     38 
     39   /**
     40    * Sends the request body returned by {@link #createRequestBody} to the
     41    * remote peer.
     42    */
     43   void writeRequestBody(RetryableSink requestBody) throws IOException;
     44 
     45   /** Flush the request to the underlying socket. */
     46   void finishRequest() throws IOException;
     47 
     48   /** Read and return response headers. */
     49   Response.Builder readResponseHeaders() throws IOException;
     50 
     51   /** Returns a stream that reads the response body. */
     52   ResponseBody openResponseBody(Response response) throws IOException;
     53 
     54   /**
     55    * Configures the response body to pool or close the socket connection when
     56    * the response body is closed.
     57    */
     58   void releaseConnectionOnIdle() throws IOException;
     59 
     60   void disconnect(HttpEngine engine) throws IOException;
     61 
     62   /**
     63    * Returns true if the socket connection held by this transport can be reused
     64    * for a follow-up exchange.
     65    */
     66   boolean canReuseConnection();
     67 }
     68