001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http; 029 030import java.io.IOException; 031 032/** 033 * A client-side HTTP connection, which can be used for sending 034 * requests and receiving responses. 035 * 036 * @since 4.0 037 */ 038public interface HttpClientConnection extends HttpConnection { 039 040 /** 041 * Checks if response data is available from the connection. May wait for 042 * the specified time until some data becomes available. Note that some 043 * implementations may completely ignore the timeout parameter. 044 * 045 * @param timeout the maximum time in milliseconds to wait for data 046 * @return true if data is available; false if there was no data available 047 * even after waiting for {@code timeout} milliseconds. 048 * @throws IOException if an error happens on the connection 049 */ 050 boolean isResponseAvailable(int timeout) 051 throws IOException; 052 053 /** 054 * Sends the request line and all headers over the connection. 055 * @param request the request whose headers to send. 056 * @throws HttpException in case of HTTP protocol violation 057 * @throws IOException in case of an I/O error 058 */ 059 void sendRequestHeader(HttpRequest request) 060 throws HttpException, IOException; 061 062 /** 063 * Sends the request entity over the connection. 064 * @param request the request whose entity to send. 065 * @throws HttpException in case of HTTP protocol violation 066 * @throws IOException in case of an I/O error 067 */ 068 void sendRequestEntity(HttpEntityEnclosingRequest request) 069 throws HttpException, IOException; 070 071 /** 072 * Receives the request line and headers of the next response available from 073 * this connection. The caller should examine the HttpResponse object to 074 * find out if it should try to receive a response entity as well. 075 * 076 * @return a new HttpResponse object with status line and headers 077 * initialized. 078 * @throws HttpException in case of HTTP protocol violation 079 * @throws IOException in case of an I/O error 080 */ 081 HttpResponse receiveResponseHeader() 082 throws HttpException, IOException; 083 084 /** 085 * Receives the next response entity available from this connection and 086 * attaches it to an existing HttpResponse object. 087 * 088 * @param response the response to attach the entity to 089 * @throws HttpException in case of HTTP protocol violation 090 * @throws IOException in case of an I/O error 091 */ 092 void receiveResponseEntity(HttpResponse response) 093 throws HttpException, IOException; 094 095 /** 096 * Writes out all pending buffered data over the open connection. 097 * 098 * @throws IOException in case of an I/O error 099 */ 100 void flush() throws IOException; 101 102}