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; 29 30 import java.io.IOException; 31 import java.net.SocketAddress; 32 33 import javax.net.ssl.SSLSession; 34 35 /** 36 * A generic HTTP connection, useful on client and server side. 37 * 38 * @since 4.0 39 */ 40 public interface HttpConnection extends SocketModalCloseable { 41 42 /** 43 * Closes this connection gracefully. This method will attempt to flush the internal output 44 * buffer prior to closing the underlying socket. This method MUST NOT be called from a 45 * different thread to force shutdown of the connection. Use {@link #close shutdown} instead. 46 */ 47 @Override 48 void close() throws IOException; 49 50 /** 51 * Returns this connection's endpoint details. 52 * 53 * @return this connection's endpoint details. 54 */ 55 EndpointDetails getEndpointDetails(); 56 57 /** 58 * Returns this connection's local address or {@code null} if it is not bound yet. 59 * 60 * @return this connection's local address or {@code null} if it is not bound yet. 61 * @since 5.0 62 */ 63 SocketAddress getLocalAddress(); 64 65 /** 66 * Returns this connection's remote address or {@code null} if it is not connected yet or 67 * unconnected. 68 * 69 * @return this connection's remote address or {@code null} if it is not connected yet or 70 * unconnected. 71 * @since 5.0 72 */ 73 SocketAddress getRemoteAddress(); 74 75 /** 76 * Returns this connection's protocol version or {@code null} if unknown. 77 * 78 * @return this connection's protocol version or {@code null} if unknown. 79 * @since 5.0 80 */ 81 ProtocolVersion getProtocolVersion(); 82 83 /** 84 * Returns this connection's SSL session or {@code null} if TLS has not been activated. 85 * 86 * @return this connection's SSL session or {@code null} if TLS has not been activated. 87 */ 88 SSLSession getSSLSession(); 89 90 /** 91 * Checks if this connection is open. 92 * 93 * @return true if it is open, false if it is closed. 94 */ 95 boolean isOpen(); 96 97 }