1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.hc.core5.http.io; 29 30 import java.io.IOException; 31 32 import org.apache.hc.core5.http.ClassicHttpRequest; 33 import org.apache.hc.core5.http.ClassicHttpResponse; 34 import org.apache.hc.core5.http.HttpException; 35 36 /** 37 * A client-side HTTP connection, which can be used for sending 38 * requests and receiving responses. 39 * 40 * @since 4.0 41 */ 42 public interface HttpClientConnection extends BHttpConnection { 43 44 /** 45 * Checks whether this connection is in a consistent state. 46 * 47 * @return {@code true} if the connection is known to be 48 * in a inconsistent state and cannot be re-used. 49 * 50 * @see #terminateRequest(ClassicHttpRequest) 51 * 52 * @since 5.0 53 */ 54 boolean isConsistent(); 55 56 /** 57 * Sends the request line and all headers over the connection. 58 * @param request the request whose headers to send. 59 * @throws HttpException in case of HTTP protocol violation 60 * @throws IOException in case of an I/O error 61 */ 62 void sendRequestHeader(ClassicHttpRequest request) 63 throws HttpException, IOException; 64 65 /** 66 * Terminates request prematurely potentially leaving 67 * the connection in a inconsistent state. 68 * 69 * @param request the request to be terminated prematurely. 70 * @throws HttpException 71 * @throws IOException 72 * 73 * @see #isConsistent() 74 * 75 * @since 5.0 76 */ 77 void terminateRequest(ClassicHttpRequest request) 78 throws HttpException, IOException; 79 80 /** 81 * Sends the request entity over the connection. 82 * @param request the request whose entity to send. 83 * @throws HttpException in case of HTTP protocol violation 84 * @throws IOException in case of an I/O error 85 */ 86 void sendRequestEntity(ClassicHttpRequest request) 87 throws HttpException, IOException; 88 89 /** 90 * Receives the request line and headers of the next response available from 91 * this connection. The caller should examine the HttpResponse object to 92 * find out if it should try to receive a response entity as well. 93 * 94 * @return a new HttpResponse object with status line and headers 95 * initialized. 96 * @throws HttpException in case of HTTP protocol violation 97 * @throws IOException in case of an I/O error 98 */ 99 ClassicHttpResponse receiveResponseHeader() 100 throws HttpException, IOException; 101 102 /** 103 * Receives the next response entity available from this connection and 104 * attaches it to an existing HttpResponse object. 105 * 106 * @param response the response to attach the entity to 107 * @throws HttpException in case of HTTP protocol violation 108 * @throws IOException in case of an I/O error 109 */ 110 void receiveResponseEntity(ClassicHttpResponse response) 111 throws HttpException, IOException; 112 113 }