Transport.java revision c3f6f16bd4a2338e88275641b9f2f56e816ca377
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 17package libcore.net.http; 18 19import java.io.IOException; 20import java.io.InputStream; 21import java.io.OutputStream; 22import java.net.CacheRequest; 23 24interface Transport { 25 /** 26 * Returns an output stream where the request body can be written. The 27 * returned stream will of one of two types: 28 * <ul> 29 * <li><strong>Direct.</strong> Bytes are written to the socket and 30 * forgotten. This is most efficient, particularly for large request 31 * bodies. The returned stream may be buffered; the caller must call 32 * {@link #flushRequest} before reading the response.</li> 33 * <li><strong>Buffered.</strong> Bytes are written to an in memory 34 * buffer, and must be explicitly flushed with a call to {@link 35 * #writeRequestBody}. This allows HTTP authorization (401, 407) 36 * responses to be retransmitted transparently.</li> 37 * </ul> 38 */ 39 // TODO: don't bother retransmitting the request body? It's quite a corner 40 // case and there's uncertainty whether Firefox or Chrome do this 41 OutputStream createRequestBody() throws IOException; 42 43 /** 44 * This should update the HTTP engine's sentRequestMillis field. 45 */ 46 void writeRequestHeaders() throws IOException; 47 48 /** 49 * Sends the request body returned by {@link #createRequestBody} to the 50 * remote peer. 51 */ 52 void writeRequestBody(RetryableOutputStream requestBody) throws IOException; 53 54 /** 55 * Flush the request body to the underlying socket. 56 */ 57 void flushRequest() throws IOException; 58 59 /** 60 * Read response headers and update the cookie manager. 61 */ 62 ResponseHeaders readResponseHeaders() throws IOException; 63 64 // TODO: make this the content stream? 65 InputStream getTransferStream(CacheRequest cacheRequest) throws IOException; 66 67 /** 68 * Returns true if the underlying connection can be recycled. 69 */ 70 boolean makeReusable(OutputStream requestBodyOut, InputStream responseBodyIn); 71} 72