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 HttpStream { 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 void setHttpEngine(HttpEngine httpEngine); 55 56 /** 57 * Cancel this stream. Resources held by this stream will be cleaned up, though not synchronously. 58 * That may happen later by the connection pool thread. 59 */ 60 void cancel(); 61 } 62