Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * ==================================================================== |
michael@0 | 3 | * Licensed to the Apache Software Foundation (ASF) under one |
michael@0 | 4 | * or more contributor license agreements. See the NOTICE file |
michael@0 | 5 | * distributed with this work for additional information |
michael@0 | 6 | * regarding copyright ownership. The ASF licenses this file |
michael@0 | 7 | * to you under the Apache License, Version 2.0 (the |
michael@0 | 8 | * "License"); you may not use this file except in compliance |
michael@0 | 9 | * with the License. You may obtain a copy of the License at |
michael@0 | 10 | * |
michael@0 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 12 | * |
michael@0 | 13 | * Unless required by applicable law or agreed to in writing, |
michael@0 | 14 | * software distributed under the License is distributed on an |
michael@0 | 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
michael@0 | 16 | * KIND, either express or implied. See the License for the |
michael@0 | 17 | * specific language governing permissions and limitations |
michael@0 | 18 | * under the License. |
michael@0 | 19 | * ==================================================================== |
michael@0 | 20 | * |
michael@0 | 21 | * This software consists of voluntary contributions made by many |
michael@0 | 22 | * individuals on behalf of the Apache Software Foundation. For more |
michael@0 | 23 | * information on the Apache Software Foundation, please see |
michael@0 | 24 | * <http://www.apache.org/>. |
michael@0 | 25 | * |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | package ch.boye.httpclientandroidlib.conn; |
michael@0 | 29 | |
michael@0 | 30 | import java.io.IOException; |
michael@0 | 31 | import java.util.concurrent.TimeUnit; |
michael@0 | 32 | |
michael@0 | 33 | import javax.net.ssl.SSLSession; |
michael@0 | 34 | |
michael@0 | 35 | import ch.boye.httpclientandroidlib.HttpClientConnection; |
michael@0 | 36 | import ch.boye.httpclientandroidlib.HttpHost; |
michael@0 | 37 | import ch.boye.httpclientandroidlib.params.HttpParams; |
michael@0 | 38 | import ch.boye.httpclientandroidlib.protocol.HttpContext; |
michael@0 | 39 | |
michael@0 | 40 | import ch.boye.httpclientandroidlib.conn.routing.HttpRoute; |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * A client-side connection with advanced connection logic. |
michael@0 | 44 | * Instances are typically obtained from a connection manager. |
michael@0 | 45 | * |
michael@0 | 46 | * @since 4.0 |
michael@0 | 47 | */ |
michael@0 | 48 | public interface ManagedClientConnection extends |
michael@0 | 49 | HttpClientConnection, HttpRoutedConnection, ConnectionReleaseTrigger { |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * Indicates whether this connection is secure. |
michael@0 | 53 | * The return value is well-defined only while the connection is open. |
michael@0 | 54 | * It may change even while the connection is open. |
michael@0 | 55 | * |
michael@0 | 56 | * @return <code>true</code> if this connection is secure, |
michael@0 | 57 | * <code>false</code> otherwise |
michael@0 | 58 | */ |
michael@0 | 59 | boolean isSecure(); |
michael@0 | 60 | |
michael@0 | 61 | /** |
michael@0 | 62 | * Obtains the current route of this connection. |
michael@0 | 63 | * |
michael@0 | 64 | * @return the route established so far, or |
michael@0 | 65 | * <code>null</code> if not connected |
michael@0 | 66 | */ |
michael@0 | 67 | HttpRoute getRoute(); |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Obtains the SSL session of the underlying connection, if any. |
michael@0 | 71 | * If this connection is open, and the underlying socket is an |
michael@0 | 72 | * {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of |
michael@0 | 73 | * that socket is obtained. This is a potentially blocking operation. |
michael@0 | 74 | * <br/> |
michael@0 | 75 | * <b>Note:</b> Whether the underlying socket is an SSL socket |
michael@0 | 76 | * can not necessarily be determined via {@link #isSecure}. |
michael@0 | 77 | * Plain sockets may be considered secure, for example if they are |
michael@0 | 78 | * connected to a known host in the same network segment. |
michael@0 | 79 | * On the other hand, SSL sockets may be considered insecure, |
michael@0 | 80 | * for example depending on the chosen cipher suite. |
michael@0 | 81 | * |
michael@0 | 82 | * @return the underlying SSL session if available, |
michael@0 | 83 | * <code>null</code> otherwise |
michael@0 | 84 | */ |
michael@0 | 85 | SSLSession getSSLSession(); |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Opens this connection according to the given route. |
michael@0 | 89 | * |
michael@0 | 90 | * @param route the route along which to open. It will be opened to |
michael@0 | 91 | * the first proxy if present, or directly to the target. |
michael@0 | 92 | * @param context the context for opening this connection |
michael@0 | 93 | * @param params the parameters for opening this connection |
michael@0 | 94 | * |
michael@0 | 95 | * @throws IOException in case of a problem |
michael@0 | 96 | */ |
michael@0 | 97 | void open(HttpRoute route, HttpContext context, HttpParams params) |
michael@0 | 98 | throws IOException; |
michael@0 | 99 | |
michael@0 | 100 | /** |
michael@0 | 101 | * Indicates that a tunnel to the target has been established. |
michael@0 | 102 | * The route is the one previously passed to {@link #open open}. |
michael@0 | 103 | * Subsequently, {@link #layerProtocol layerProtocol} can be called |
michael@0 | 104 | * to layer the TLS/SSL protocol on top of the tunnelled connection. |
michael@0 | 105 | * <br/> |
michael@0 | 106 | * <b>Note:</b> In HttpClient 3, a call to the corresponding method |
michael@0 | 107 | * would automatically trigger the layering of the TLS/SSL protocol. |
michael@0 | 108 | * This is not the case anymore, you can establish a tunnel without |
michael@0 | 109 | * layering a new protocol over the connection. |
michael@0 | 110 | * |
michael@0 | 111 | * @param secure <code>true</code> if the tunnel should be considered |
michael@0 | 112 | * secure, <code>false</code> otherwise |
michael@0 | 113 | * @param params the parameters for tunnelling this connection |
michael@0 | 114 | * |
michael@0 | 115 | * @throws IOException in case of a problem |
michael@0 | 116 | */ |
michael@0 | 117 | void tunnelTarget(boolean secure, HttpParams params) |
michael@0 | 118 | throws IOException; |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * Indicates that a tunnel to an intermediate proxy has been established. |
michael@0 | 122 | * This is used exclusively for so-called <i>proxy chains</i>, where |
michael@0 | 123 | * a request has to pass through multiple proxies before reaching the |
michael@0 | 124 | * target. In that case, all proxies but the last need to be tunnelled |
michael@0 | 125 | * when establishing the connection. Tunnelling of the last proxy to the |
michael@0 | 126 | * target is optional and would be indicated via {@link #tunnelTarget}. |
michael@0 | 127 | * |
michael@0 | 128 | * @param next the proxy to which the tunnel was established. |
michael@0 | 129 | * This is <i>not</i> the proxy <i>through</i> which |
michael@0 | 130 | * the tunnel was established, but the new end point |
michael@0 | 131 | * of the tunnel. The tunnel does <i>not</i> yet |
michael@0 | 132 | * reach to the target, use {@link #tunnelTarget} |
michael@0 | 133 | * to indicate an end-to-end tunnel. |
michael@0 | 134 | * @param secure <code>true</code> if the connection should be |
michael@0 | 135 | * considered secure, <code>false</code> otherwise |
michael@0 | 136 | * @param params the parameters for tunnelling this connection |
michael@0 | 137 | * |
michael@0 | 138 | * @throws IOException in case of a problem |
michael@0 | 139 | */ |
michael@0 | 140 | void tunnelProxy(HttpHost next, boolean secure, HttpParams params) |
michael@0 | 141 | throws IOException; |
michael@0 | 142 | |
michael@0 | 143 | /** |
michael@0 | 144 | * Layers a new protocol on top of a {@link #tunnelTarget tunnelled} |
michael@0 | 145 | * connection. This is typically used to create a TLS/SSL connection |
michael@0 | 146 | * through a proxy. |
michael@0 | 147 | * The route is the one previously passed to {@link #open open}. |
michael@0 | 148 | * It is not guaranteed that the layered connection is |
michael@0 | 149 | * {@link #isSecure secure}. |
michael@0 | 150 | * |
michael@0 | 151 | * @param context the context for layering on top of this connection |
michael@0 | 152 | * @param params the parameters for layering on top of this connection |
michael@0 | 153 | * |
michael@0 | 154 | * @throws IOException in case of a problem |
michael@0 | 155 | */ |
michael@0 | 156 | void layerProtocol(HttpContext context, HttpParams params) |
michael@0 | 157 | throws IOException; |
michael@0 | 158 | |
michael@0 | 159 | /** |
michael@0 | 160 | * Marks this connection as being in a reusable communication state. |
michael@0 | 161 | * The checkpoints for reuseable communication states (in the absence |
michael@0 | 162 | * of pipelining) are before sending a request and after receiving |
michael@0 | 163 | * the response in its entirety. |
michael@0 | 164 | * The connection will automatically clear the checkpoint when |
michael@0 | 165 | * used for communication. A call to this method indicates that |
michael@0 | 166 | * the next checkpoint has been reached. |
michael@0 | 167 | * <br/> |
michael@0 | 168 | * A reusable communication state is necessary but not sufficient |
michael@0 | 169 | * for the connection to be reused. |
michael@0 | 170 | * A {@link #getRoute route} mismatch, the connection being closed, |
michael@0 | 171 | * or other circumstances might prevent reuse. |
michael@0 | 172 | */ |
michael@0 | 173 | void markReusable(); |
michael@0 | 174 | |
michael@0 | 175 | /** |
michael@0 | 176 | * Marks this connection as not being in a reusable state. |
michael@0 | 177 | * This can be used immediately before releasing this connection |
michael@0 | 178 | * to prevent its reuse. Reasons for preventing reuse include |
michael@0 | 179 | * error conditions and the evaluation of a |
michael@0 | 180 | * {@link ch.boye.httpclientandroidlib.ConnectionReuseStrategy reuse strategy}. |
michael@0 | 181 | * <br/> |
michael@0 | 182 | * <b>Note:</b> |
michael@0 | 183 | * It is <i>not</i> necessary to call here before writing to |
michael@0 | 184 | * or reading from this connection. Communication attempts will |
michael@0 | 185 | * automatically unmark the state as non-reusable. It can then |
michael@0 | 186 | * be switched back using {@link #markReusable markReusable}. |
michael@0 | 187 | */ |
michael@0 | 188 | void unmarkReusable(); |
michael@0 | 189 | |
michael@0 | 190 | /** |
michael@0 | 191 | * Indicates whether this connection is in a reusable communication state. |
michael@0 | 192 | * See {@link #markReusable markReusable} and |
michael@0 | 193 | * {@link #unmarkReusable unmarkReusable} for details. |
michael@0 | 194 | * |
michael@0 | 195 | * @return <code>true</code> if this connection is marked as being in |
michael@0 | 196 | * a reusable communication state, |
michael@0 | 197 | * <code>false</code> otherwise |
michael@0 | 198 | */ |
michael@0 | 199 | boolean isMarkedReusable(); |
michael@0 | 200 | |
michael@0 | 201 | /** |
michael@0 | 202 | * Assigns a state object to this connection. Connection managers may make |
michael@0 | 203 | * use of the connection state when allocating persistent connections. |
michael@0 | 204 | * |
michael@0 | 205 | * @param state The state object |
michael@0 | 206 | */ |
michael@0 | 207 | void setState(Object state); |
michael@0 | 208 | |
michael@0 | 209 | /** |
michael@0 | 210 | * Returns the state object associated with this connection. |
michael@0 | 211 | * |
michael@0 | 212 | * @return The state object |
michael@0 | 213 | */ |
michael@0 | 214 | Object getState(); |
michael@0 | 215 | |
michael@0 | 216 | /** |
michael@0 | 217 | * Sets the duration that this connection can remain idle before it is |
michael@0 | 218 | * reused. The connection should not be used again if this time elapses. The |
michael@0 | 219 | * idle duration must be reset after each request sent over this connection. |
michael@0 | 220 | * The elapsed time starts counting when the connection is released, which |
michael@0 | 221 | * is typically after the headers (and any response body, if present) is |
michael@0 | 222 | * fully consumed. |
michael@0 | 223 | */ |
michael@0 | 224 | void setIdleDuration(long duration, TimeUnit unit); |
michael@0 | 225 | |
michael@0 | 226 | } |