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