author | dfuchs |
Fri, 30 Aug 2019 15:42:27 +0100 | |
branch | JDK-8229867-branch |
changeset 57968 | 8595871a5446 |
parent 53563 | a4b7ea85d668 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57968 | 2 |
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.net.www.http; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.net.*; |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
30 |
import java.util.Locale; |
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
31 |
import java.util.Objects; |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
34943
diff
changeset
|
32 |
import java.util.Properties; |
57968 | 33 |
import java.util.concurrent.locks.Lock; |
34 |
import java.util.concurrent.locks.ReentrantLock; |
|
35 |
||
2 | 36 |
import sun.net.NetworkClient; |
37 |
import sun.net.ProgressSource; |
|
38 |
import sun.net.www.MessageHeader; |
|
39 |
import sun.net.www.HeaderParser; |
|
40 |
import sun.net.www.MeteredStream; |
|
41 |
import sun.net.www.ParseUtil; |
|
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
42 |
import sun.net.www.protocol.http.AuthenticatorKeys; |
2 | 43 |
import sun.net.www.protocol.http.HttpURLConnection; |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3288
diff
changeset
|
44 |
import sun.util.logging.PlatformLogger; |
14008
b572c1f3a7ad
7199219: Proxy-Connection headers set incorrectly when a HttpClient is retrieved from the Keep Alive Cache
robm
parents:
14007
diff
changeset
|
45 |
import static sun.net.www.protocol.http.HttpURLConnection.TunnelState.*; |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
34943
diff
changeset
|
46 |
import sun.security.action.GetPropertyAction; |
2 | 47 |
|
48 |
/** |
|
49 |
* @author Herb Jellinek |
|
50 |
* @author Dave Brown |
|
51 |
*/ |
|
52 |
public class HttpClient extends NetworkClient { |
|
57968 | 53 |
protected final ReentrantLock clientLock = new ReentrantLock(); |
54 |
||
2 | 55 |
// whether this httpclient comes from the cache |
56 |
protected boolean cachedHttpClient = false; |
|
57 |
||
16499
88276d2da9c0
8009251: Add proxy handling and keep-alive fixes to jsse
robm
parents:
16477
diff
changeset
|
58 |
protected boolean inCache; |
2 | 59 |
|
60 |
// Http requests we send |
|
61 |
MessageHeader requests; |
|
62 |
||
63 |
// Http data we send with the headers |
|
64 |
PosterOutputStream poster = null; |
|
65 |
||
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
66 |
// true if we are in streaming mode (fixed length or chunked) |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
67 |
boolean streaming; |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
68 |
|
2 | 69 |
// if we've had one io error |
70 |
boolean failedOnce = false; |
|
71 |
||
72 |
/** Response code for CONTINUE */ |
|
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
73 |
private boolean ignoreContinue = true; |
2 | 74 |
private static final int HTTP_CONTINUE = 100; |
75 |
||
76 |
/** Default port number for http daemons. REMIND: make these private */ |
|
77 |
static final int httpPortNumber = 80; |
|
78 |
||
79 |
/** return default port number (subclasses may override) */ |
|
80 |
protected int getDefaultPort () { return httpPortNumber; } |
|
81 |
||
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
31061
diff
changeset
|
82 |
private static int getDefaultPort(String proto) { |
2 | 83 |
if ("http".equalsIgnoreCase(proto)) |
84 |
return 80; |
|
85 |
if ("https".equalsIgnoreCase(proto)) |
|
86 |
return 443; |
|
87 |
return -1; |
|
88 |
} |
|
89 |
||
90 |
/* All proxying (generic as well as instance-specific) may be |
|
91 |
* disabled through use of this flag |
|
92 |
*/ |
|
93 |
protected boolean proxyDisabled; |
|
94 |
||
95 |
// are we using proxy in this instance? |
|
96 |
public boolean usingProxy = false; |
|
97 |
// target host, port for the URL |
|
98 |
protected String host; |
|
99 |
protected int port; |
|
100 |
||
101 |
/* where we cache currently open, persistent connections */ |
|
102 |
protected static KeepAliveCache kac = new KeepAliveCache(); |
|
103 |
||
104 |
private static boolean keepAliveProp = true; |
|
105 |
||
106 |
// retryPostProp is true by default so as to preserve behavior |
|
107 |
// from previous releases. |
|
108 |
private static boolean retryPostProp = true; |
|
109 |
||
44753 | 110 |
/* Value of the system property jdk.ntlm.cache; |
111 |
if false, then NTLM connections will not be cached. |
|
112 |
The default value is 'true'. */ |
|
113 |
private static final boolean cacheNTLMProp; |
|
44755 | 114 |
/* Value of the system property jdk.spnego.cache; |
115 |
if false, then connections authentified using the Negotiate/Kerberos |
|
116 |
scheme will not be cached. |
|
117 |
The default value is 'true'. */ |
|
118 |
private static final boolean cacheSPNEGOProp; |
|
44753 | 119 |
|
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
32649
diff
changeset
|
120 |
volatile boolean keepingAlive; /* this is a keep-alive connection */ |
44753 | 121 |
volatile boolean disableKeepAlive;/* keep-alive has been disabled for this |
122 |
connection - this will be used when |
|
123 |
recomputing the value of keepingAlive */ |
|
2 | 124 |
int keepAliveConnections = -1; /* number of keep-alives left */ |
125 |
||
126 |
/**Idle timeout value, in milliseconds. Zero means infinity, |
|
127 |
* iff keepingAlive=true. |
|
128 |
* Unfortunately, we can't always believe this one. If I'm connected |
|
129 |
* through a Netscape proxy to a server that sent me a keep-alive |
|
130 |
* time of 15 sec, the proxy unilaterally terminates my connection |
|
131 |
* after 5 sec. So we have to hard code our effective timeout to |
|
132 |
* 4 sec for the case where we're using a proxy. *SIGH* |
|
133 |
*/ |
|
134 |
int keepAliveTimeout = 0; |
|
135 |
||
136 |
/** whether the response is to be cached */ |
|
137 |
private CacheRequest cacheRequest = null; |
|
138 |
||
139 |
/** Url being fetched. */ |
|
140 |
protected URL url; |
|
141 |
||
142 |
/* if set, the client will be reused and must not be put in cache */ |
|
143 |
public boolean reuse = false; |
|
144 |
||
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
145 |
// Traffic capture tool, if configured. See HttpCapture class for info |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
146 |
private HttpCapture capture = null; |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
147 |
|
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
148 |
private static final PlatformLogger logger = HttpURLConnection.getHttpLogger(); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
149 |
private static void logFinest(String msg) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16499
diff
changeset
|
150 |
if (logger.isLoggable(PlatformLogger.Level.FINEST)) { |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
151 |
logger.finest(msg); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
152 |
} |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
153 |
} |
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
154 |
|
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
155 |
protected volatile String authenticatorKey; |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
156 |
|
2 | 157 |
/** |
158 |
* A NOP method kept for backwards binary compatibility |
|
159 |
* @deprecated -- system properties are no longer cached. |
|
160 |
*/ |
|
161 |
@Deprecated |
|
162 |
public static synchronized void resetProperties() { |
|
163 |
} |
|
164 |
||
165 |
int getKeepAliveTimeout() { |
|
166 |
return keepAliveTimeout; |
|
167 |
} |
|
168 |
||
169 |
static { |
|
37781
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37593
diff
changeset
|
170 |
Properties props = GetPropertyAction.privilegedGetProperties(); |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
34943
diff
changeset
|
171 |
String keepAlive = props.getProperty("http.keepAlive"); |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
34943
diff
changeset
|
172 |
String retryPost = props.getProperty("sun.net.http.retryPost"); |
44753 | 173 |
String cacheNTLM = props.getProperty("jdk.ntlm.cache"); |
44755 | 174 |
String cacheSPNEGO = props.getProperty("jdk.spnego.cache"); |
2 | 175 |
|
176 |
if (keepAlive != null) { |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
34943
diff
changeset
|
177 |
keepAliveProp = Boolean.parseBoolean(keepAlive); |
2 | 178 |
} else { |
179 |
keepAliveProp = true; |
|
180 |
} |
|
181 |
||
182 |
if (retryPost != null) { |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
34943
diff
changeset
|
183 |
retryPostProp = Boolean.parseBoolean(retryPost); |
44753 | 184 |
} else { |
2 | 185 |
retryPostProp = true; |
44753 | 186 |
} |
187 |
||
188 |
if (cacheNTLM != null) { |
|
189 |
cacheNTLMProp = Boolean.parseBoolean(cacheNTLM); |
|
190 |
} else { |
|
191 |
cacheNTLMProp = true; |
|
192 |
} |
|
2 | 193 |
|
44755 | 194 |
if (cacheSPNEGO != null) { |
195 |
cacheSPNEGOProp = Boolean.parseBoolean(cacheSPNEGO); |
|
196 |
} else { |
|
197 |
cacheSPNEGOProp = true; |
|
198 |
} |
|
2 | 199 |
} |
200 |
||
201 |
/** |
|
202 |
* @return true iff http keep alive is set (i.e. enabled). Defaults |
|
203 |
* to true if the system property http.keepAlive isn't set. |
|
204 |
*/ |
|
205 |
public boolean getHttpKeepAliveSet() { |
|
206 |
return keepAliveProp; |
|
207 |
} |
|
208 |
||
209 |
||
210 |
protected HttpClient() { |
|
211 |
} |
|
212 |
||
213 |
private HttpClient(URL url) |
|
214 |
throws IOException { |
|
215 |
this(url, (String)null, -1, false); |
|
216 |
} |
|
217 |
||
218 |
protected HttpClient(URL url, |
|
219 |
boolean proxyDisabled) throws IOException { |
|
220 |
this(url, null, -1, proxyDisabled); |
|
221 |
} |
|
222 |
||
223 |
/* This package-only CTOR should only be used for FTP piggy-backed on HTTP |
|
53563 | 224 |
* URL's that use this won't take advantage of keep-alive. |
2 | 225 |
* Additionally, this constructor may be used as a last resort when the |
226 |
* first HttpClient gotten through New() failed (probably b/c of a |
|
227 |
* Keep-Alive mismatch). |
|
228 |
* |
|
229 |
* XXX That documentation is wrong ... it's not package-private any more |
|
230 |
*/ |
|
231 |
public HttpClient(URL url, String proxyHost, int proxyPort) |
|
232 |
throws IOException { |
|
233 |
this(url, proxyHost, proxyPort, false); |
|
234 |
} |
|
235 |
||
236 |
protected HttpClient(URL url, Proxy p, int to) throws IOException { |
|
237 |
proxy = (p == null) ? Proxy.NO_PROXY : p; |
|
238 |
this.host = url.getHost(); |
|
239 |
this.url = url; |
|
240 |
port = url.getPort(); |
|
241 |
if (port == -1) { |
|
242 |
port = getDefaultPort(); |
|
243 |
} |
|
244 |
setConnectTimeout(to); |
|
245 |
||
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
246 |
capture = HttpCapture.getCapture(url); |
2 | 247 |
openServer(); |
248 |
} |
|
249 |
||
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
31061
diff
changeset
|
250 |
protected static Proxy newHttpProxy(String proxyHost, int proxyPort, |
2 | 251 |
String proto) { |
252 |
if (proxyHost == null || proto == null) |
|
253 |
return Proxy.NO_PROXY; |
|
254 |
int pport = proxyPort < 0 ? getDefaultPort(proto) : proxyPort; |
|
255 |
InetSocketAddress saddr = InetSocketAddress.createUnresolved(proxyHost, pport); |
|
256 |
return new Proxy(Proxy.Type.HTTP, saddr); |
|
257 |
} |
|
258 |
||
259 |
/* |
|
260 |
* This constructor gives "ultimate" flexibility, including the ability |
|
261 |
* to bypass implicit proxying. Sometimes we need to be using tunneling |
|
262 |
* (transport or network level) instead of proxying (application level), |
|
263 |
* for example when we don't want the application level data to become |
|
264 |
* visible to third parties. |
|
265 |
* |
|
266 |
* @param url the URL to which we're connecting |
|
267 |
* @param proxy proxy to use for this URL (e.g. forwarding) |
|
268 |
* @param proxyPort proxy port to use for this URL |
|
269 |
* @param proxyDisabled true to disable default proxying |
|
270 |
*/ |
|
271 |
private HttpClient(URL url, String proxyHost, int proxyPort, |
|
272 |
boolean proxyDisabled) |
|
273 |
throws IOException { |
|
274 |
this(url, proxyDisabled ? Proxy.NO_PROXY : |
|
275 |
newHttpProxy(proxyHost, proxyPort, "http"), -1); |
|
276 |
} |
|
277 |
||
278 |
public HttpClient(URL url, String proxyHost, int proxyPort, |
|
279 |
boolean proxyDisabled, int to) |
|
280 |
throws IOException { |
|
281 |
this(url, proxyDisabled ? Proxy.NO_PROXY : |
|
282 |
newHttpProxy(proxyHost, proxyPort, "http"), to); |
|
283 |
} |
|
284 |
||
285 |
/* This class has no public constructor for HTTP. This method is used to |
|
21278 | 286 |
* get an HttpClient to the specified URL. If there's currently an |
2 | 287 |
* active HttpClient to that server/port, you'll get that one. |
288 |
*/ |
|
289 |
public static HttpClient New(URL url) |
|
290 |
throws IOException { |
|
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
291 |
return HttpClient.New(url, Proxy.NO_PROXY, -1, true, null); |
2 | 292 |
} |
293 |
||
294 |
public static HttpClient New(URL url, boolean useCache) |
|
295 |
throws IOException { |
|
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
296 |
return HttpClient.New(url, Proxy.NO_PROXY, -1, useCache, null); |
2 | 297 |
} |
298 |
||
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
299 |
public static HttpClient New(URL url, Proxy p, int to, boolean useCache, |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
300 |
HttpURLConnection httpuc) throws IOException |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
301 |
{ |
2 | 302 |
if (p == null) { |
303 |
p = Proxy.NO_PROXY; |
|
304 |
} |
|
305 |
HttpClient ret = null; |
|
306 |
/* see if one's already around */ |
|
307 |
if (useCache) { |
|
51 | 308 |
ret = kac.get(url, null); |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
309 |
if (ret != null && httpuc != null && |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
310 |
httpuc.streaming() && |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
311 |
httpuc.getRequestMethod() == "POST") { |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
312 |
if (!ret.available()) { |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
313 |
ret.inCache = false; |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
314 |
ret.closeServer(); |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
315 |
ret = null; |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
316 |
} |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
317 |
} |
2 | 318 |
if (ret != null) { |
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
319 |
String ak = httpuc == null ? AuthenticatorKeys.DEFAULT |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
320 |
: httpuc.getAuthenticatorKey(); |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
321 |
boolean compatible = Objects.equals(ret.proxy, p) |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
322 |
&& Objects.equals(ret.getAuthenticatorKey(), ak); |
57968 | 323 |
final Lock lock = ret.clientLock; |
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
324 |
if (compatible) { |
57968 | 325 |
lock.lock(); |
326 |
try { |
|
2 | 327 |
ret.cachedHttpClient = true; |
328 |
assert ret.inCache; |
|
329 |
ret.inCache = false; |
|
14008
b572c1f3a7ad
7199219: Proxy-Connection headers set incorrectly when a HttpClient is retrieved from the Keep Alive Cache
robm
parents:
14007
diff
changeset
|
330 |
if (httpuc != null && ret.needsTunneling()) |
b572c1f3a7ad
7199219: Proxy-Connection headers set incorrectly when a HttpClient is retrieved from the Keep Alive Cache
robm
parents:
14007
diff
changeset
|
331 |
httpuc.setTunnelState(TUNNELING); |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
332 |
logFinest("KeepAlive stream retrieved from the cache, " + ret); |
57968 | 333 |
} finally { |
334 |
lock.unlock(); |
|
2 | 335 |
} |
336 |
} else { |
|
337 |
// We cannot return this connection to the cache as it's |
|
338 |
// KeepAliveTimeout will get reset. We simply close the connection. |
|
339 |
// This should be fine as it is very rare that a connection |
|
340 |
// to the same host will not use the same proxy. |
|
57968 | 341 |
lock.lock(); |
342 |
try { |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
343 |
ret.inCache = false; |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
344 |
ret.closeServer(); |
57968 | 345 |
} finally { |
346 |
lock.unlock(); |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
347 |
} |
2 | 348 |
ret = null; |
349 |
} |
|
350 |
} |
|
351 |
} |
|
352 |
if (ret == null) { |
|
353 |
ret = new HttpClient(url, p, to); |
|
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
354 |
if (httpuc != null) { |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
355 |
ret.authenticatorKey = httpuc.getAuthenticatorKey(); |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
356 |
} |
2 | 357 |
} else { |
358 |
SecurityManager security = System.getSecurityManager(); |
|
359 |
if (security != null) { |
|
9775 | 360 |
if (ret.proxy == Proxy.NO_PROXY || ret.proxy == null) { |
361 |
security.checkConnect(InetAddress.getByName(url.getHost()).getHostAddress(), url.getPort()); |
|
362 |
} else { |
|
363 |
security.checkConnect(url.getHost(), url.getPort()); |
|
364 |
} |
|
2 | 365 |
} |
366 |
ret.url = url; |
|
367 |
} |
|
368 |
return ret; |
|
369 |
} |
|
370 |
||
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
371 |
public static HttpClient New(URL url, Proxy p, int to, |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
372 |
HttpURLConnection httpuc) throws IOException |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
373 |
{ |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
374 |
return New(url, p, to, true, httpuc); |
2 | 375 |
} |
376 |
||
377 |
public static HttpClient New(URL url, String proxyHost, int proxyPort, |
|
378 |
boolean useCache) |
|
379 |
throws IOException { |
|
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
380 |
return New(url, newHttpProxy(proxyHost, proxyPort, "http"), |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
381 |
-1, useCache, null); |
2 | 382 |
} |
383 |
||
384 |
public static HttpClient New(URL url, String proxyHost, int proxyPort, |
|
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
385 |
boolean useCache, int to, |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
386 |
HttpURLConnection httpuc) |
2 | 387 |
throws IOException { |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
388 |
return New(url, newHttpProxy(proxyHost, proxyPort, "http"), |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
389 |
to, useCache, httpuc); |
2 | 390 |
} |
391 |
||
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
392 |
public final String getAuthenticatorKey() { |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
393 |
String k = authenticatorKey; |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
394 |
if (k == null) return AuthenticatorKeys.DEFAULT; |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
395 |
return k; |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
396 |
} |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
37781
diff
changeset
|
397 |
|
2 | 398 |
/* return it to the cache as still usable, if: |
399 |
* 1) It's keeping alive, AND |
|
400 |
* 2) It still has some connections left, AND |
|
401 |
* 3) It hasn't had a error (PrintStream.checkError()) |
|
402 |
* 4) It hasn't timed out |
|
403 |
* |
|
404 |
* If this client is not keepingAlive, it should have been |
|
405 |
* removed from the cache in the parseHeaders() method. |
|
406 |
*/ |
|
407 |
||
408 |
public void finished() { |
|
409 |
if (reuse) /* will be reused */ |
|
410 |
return; |
|
411 |
keepAliveConnections--; |
|
412 |
poster = null; |
|
413 |
if (keepAliveConnections > 0 && isKeepingAlive() && |
|
414 |
!(serverOutput.checkError())) { |
|
415 |
/* This connection is keepingAlive && still valid. |
|
416 |
* Return it to the cache. |
|
417 |
*/ |
|
418 |
putInKeepAliveCache(); |
|
419 |
} else { |
|
420 |
closeServer(); |
|
421 |
} |
|
422 |
} |
|
423 |
||
57968 | 424 |
protected boolean available() { |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
425 |
boolean available = true; |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
426 |
int old = -1; |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
427 |
|
57968 | 428 |
clientLock.lock(); |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
429 |
try { |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
430 |
try { |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
431 |
old = serverSocket.getSoTimeout(); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
432 |
serverSocket.setSoTimeout(1); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
433 |
BufferedInputStream tmpbuf = |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
434 |
new BufferedInputStream(serverSocket.getInputStream()); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
435 |
int r = tmpbuf.read(); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
436 |
if (r == -1) { |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
437 |
logFinest("HttpClient.available(): " + |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
438 |
"read returned -1: not available"); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
439 |
available = false; |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
440 |
} |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
441 |
} catch (SocketTimeoutException e) { |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
442 |
logFinest("HttpClient.available(): " + |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
443 |
"SocketTimeout: its available"); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
444 |
} finally { |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
445 |
if (old != -1) |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
446 |
serverSocket.setSoTimeout(old); |
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
447 |
} |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
448 |
} catch (IOException e) { |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
449 |
logFinest("HttpClient.available(): " + |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
450 |
"SocketException: not available"); |
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
451 |
available = false; |
57968 | 452 |
} finally { |
453 |
clientLock.unlock(); |
|
14007
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
454 |
} |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
455 |
return available; |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
456 |
} |
2fde9d6d874a
7199862: Make sure that a connection is still alive when retrieved from KeepAliveCache in certain cases
robm
parents:
11528
diff
changeset
|
457 |
|
57968 | 458 |
protected void putInKeepAliveCache() { |
459 |
clientLock.lock(); |
|
460 |
try { |
|
461 |
if (inCache) { |
|
462 |
assert false : "Duplicate put to keep alive cache"; |
|
463 |
return; |
|
464 |
} |
|
465 |
inCache = true; |
|
466 |
kac.put(url, null, this); |
|
467 |
} finally { |
|
468 |
clientLock.unlock(); |
|
2 | 469 |
} |
470 |
} |
|
471 |
||
57968 | 472 |
protected boolean isInKeepAliveCache() { |
473 |
clientLock.lock(); |
|
474 |
try { |
|
475 |
return inCache; |
|
476 |
} finally { |
|
477 |
clientLock.unlock(); |
|
478 |
} |
|
2 | 479 |
} |
480 |
||
481 |
/* |
|
482 |
* Close an idle connection to this URL (if it exists in the |
|
483 |
* cache). |
|
484 |
*/ |
|
485 |
public void closeIdleConnection() { |
|
51 | 486 |
HttpClient http = kac.get(url, null); |
2 | 487 |
if (http != null) { |
488 |
http.closeServer(); |
|
489 |
} |
|
490 |
} |
|
491 |
||
492 |
/* We're very particular here about what our InputStream to the server |
|
493 |
* looks like for reasons that are apparent if you can decipher the |
|
494 |
* method parseHTTP(). That's why this method is overidden from the |
|
495 |
* superclass. |
|
496 |
*/ |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
497 |
@Override |
2 | 498 |
public void openServer(String server, int port) throws IOException { |
499 |
serverSocket = doConnect(server, port); |
|
500 |
try { |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
501 |
OutputStream out = serverSocket.getOutputStream(); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
502 |
if (capture != null) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
503 |
out = new HttpCaptureOutputStream(out, capture); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
504 |
} |
2 | 505 |
serverOutput = new PrintStream( |
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
506 |
new BufferedOutputStream(out), |
2 | 507 |
false, encoding); |
508 |
} catch (UnsupportedEncodingException e) { |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
10136
diff
changeset
|
509 |
throw new InternalError(encoding+" encoding not found", e); |
2 | 510 |
} |
511 |
serverSocket.setTcpNoDelay(true); |
|
512 |
} |
|
513 |
||
514 |
/* |
|
515 |
* Returns true if the http request should be tunneled through proxy. |
|
516 |
* An example where this is the case is Https. |
|
517 |
*/ |
|
518 |
public boolean needsTunneling() { |
|
519 |
return false; |
|
520 |
} |
|
521 |
||
522 |
/* |
|
523 |
* Returns true if this httpclient is from cache |
|
524 |
*/ |
|
57968 | 525 |
public boolean isCachedConnection() { |
526 |
clientLock.lock(); |
|
527 |
try { |
|
528 |
return cachedHttpClient; |
|
529 |
} finally { |
|
530 |
clientLock.unlock(); |
|
531 |
} |
|
2 | 532 |
} |
533 |
||
534 |
/* |
|
535 |
* Finish any work left after the socket connection is |
|
536 |
* established. In the normal http case, it's a NO-OP. Subclass |
|
537 |
* may need to override this. An example is Https, where for |
|
538 |
* direct connection to the origin server, ssl handshake needs to |
|
539 |
* be done; for proxy tunneling, the socket needs to be converted |
|
540 |
* into an SSL socket before ssl handshake can take place. |
|
541 |
*/ |
|
542 |
public void afterConnect() throws IOException, UnknownHostException { |
|
543 |
// NO-OP. Needs to be overwritten by HttpsClient |
|
544 |
} |
|
545 |
||
546 |
/* |
|
547 |
* call openServer in a privileged block |
|
548 |
*/ |
|
57968 | 549 |
private void privilegedOpenServer(final InetSocketAddress server) |
2 | 550 |
throws IOException |
551 |
{ |
|
57968 | 552 |
assert clientLock.isHeldByCurrentThread(); |
2 | 553 |
try { |
554 |
java.security.AccessController.doPrivileged( |
|
29986
97167d851fc4
8078467: Update core libraries to use diamond with anonymous classes
darcy
parents:
27717
diff
changeset
|
555 |
new java.security.PrivilegedExceptionAction<>() { |
51 | 556 |
public Void run() throws IOException { |
2 | 557 |
openServer(server.getHostString(), server.getPort()); |
558 |
return null; |
|
559 |
} |
|
560 |
}); |
|
561 |
} catch (java.security.PrivilegedActionException pae) { |
|
562 |
throw (IOException) pae.getException(); |
|
563 |
} |
|
564 |
} |
|
565 |
||
566 |
/* |
|
567 |
* call super.openServer |
|
568 |
*/ |
|
569 |
private void superOpenServer(final String proxyHost, |
|
570 |
final int proxyPort) |
|
571 |
throws IOException, UnknownHostException |
|
572 |
{ |
|
573 |
super.openServer(proxyHost, proxyPort); |
|
574 |
} |
|
575 |
||
576 |
/* |
|
577 |
*/ |
|
57968 | 578 |
protected void openServer() throws IOException { |
2 | 579 |
|
580 |
SecurityManager security = System.getSecurityManager(); |
|
9775 | 581 |
|
57968 | 582 |
clientLock.lock(); |
583 |
try { |
|
584 |
if (security != null) { |
|
585 |
security.checkConnect(host, port); |
|
586 |
} |
|
2 | 587 |
|
57968 | 588 |
if (keepingAlive) { // already opened |
2 | 589 |
return; |
590 |
} |
|
591 |
||
57968 | 592 |
if (url.getProtocol().equals("http") || |
593 |
url.getProtocol().equals("https")) { |
|
594 |
||
595 |
if ((proxy != null) && (proxy.type() == Proxy.Type.HTTP)) { |
|
596 |
sun.net.www.URLConnection.setProxiedHost(host); |
|
597 |
privilegedOpenServer((InetSocketAddress) proxy.address()); |
|
598 |
usingProxy = true; |
|
599 |
return; |
|
600 |
} else { |
|
601 |
// make direct connection |
|
602 |
openServer(host, port); |
|
603 |
usingProxy = false; |
|
604 |
return; |
|
605 |
} |
|
606 |
||
2 | 607 |
} else { |
57968 | 608 |
/* we're opening some other kind of url, most likely an |
609 |
* ftp url. |
|
610 |
*/ |
|
611 |
if ((proxy != null) && (proxy.type() == Proxy.Type.HTTP)) { |
|
612 |
sun.net.www.URLConnection.setProxiedHost(host); |
|
613 |
privilegedOpenServer((InetSocketAddress) proxy.address()); |
|
614 |
usingProxy = true; |
|
615 |
return; |
|
616 |
} else { |
|
617 |
// make direct connection |
|
618 |
super.openServer(host, port); |
|
619 |
usingProxy = false; |
|
620 |
return; |
|
621 |
} |
|
2 | 622 |
} |
57968 | 623 |
} finally { |
624 |
clientLock.unlock(); |
|
2 | 625 |
} |
626 |
} |
|
627 |
||
628 |
public String getURLFile() throws IOException { |
|
629 |
||
18294
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
630 |
String fileName; |
2 | 631 |
|
632 |
/** |
|
633 |
* proxyDisabled is set by subclass HttpsClient! |
|
634 |
*/ |
|
635 |
if (usingProxy && !proxyDisabled) { |
|
636 |
// Do not use URLStreamHandler.toExternalForm as the fragment |
|
637 |
// should not be part of the RequestURI. It should be an |
|
638 |
// absolute URI which does not have a fragment part. |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
24045
diff
changeset
|
639 |
StringBuilder result = new StringBuilder(128); |
2 | 640 |
result.append(url.getProtocol()); |
641 |
result.append(":"); |
|
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
47216
diff
changeset
|
642 |
if (url.getAuthority() != null && !url.getAuthority().isEmpty()) { |
2 | 643 |
result.append("//"); |
644 |
result.append(url.getAuthority()); |
|
645 |
} |
|
646 |
if (url.getPath() != null) { |
|
647 |
result.append(url.getPath()); |
|
648 |
} |
|
649 |
if (url.getQuery() != null) { |
|
650 |
result.append('?'); |
|
651 |
result.append(url.getQuery()); |
|
652 |
} |
|
653 |
||
18294
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
654 |
fileName = result.toString(); |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
655 |
} else { |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
656 |
fileName = url.getFile(); |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
657 |
|
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
47216
diff
changeset
|
658 |
if ((fileName == null) || (fileName.isEmpty())) { |
18294
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
659 |
fileName = "/"; |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
660 |
} else if (fileName.charAt(0) == '?') { |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
661 |
/* HTTP/1.1 spec says in 5.1.2. about Request-URI: |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
662 |
* "Note that the absolute path cannot be empty; if |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
663 |
* none is present in the original URI, it MUST be |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
664 |
* given as "/" (the server root)." So if the file |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
665 |
* name here has only a query string, the path is |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
666 |
* empty and we also have to add a "/". |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
667 |
*/ |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
668 |
fileName = "/" + fileName; |
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
669 |
} |
2 | 670 |
} |
18294
364814dc7391
7025238: HttpURLConnection does not handle URLs with an empty path component.
arieber
parents:
18178
diff
changeset
|
671 |
|
2 | 672 |
if (fileName.indexOf('\n') == -1) |
673 |
return fileName; |
|
674 |
else |
|
675 |
throw new java.net.MalformedURLException("Illegal character in URL"); |
|
676 |
} |
|
677 |
||
678 |
/** |
|
679 |
* @deprecated |
|
680 |
*/ |
|
681 |
@Deprecated |
|
682 |
public void writeRequests(MessageHeader head) { |
|
683 |
requests = head; |
|
684 |
requests.print(serverOutput); |
|
685 |
serverOutput.flush(); |
|
686 |
} |
|
687 |
||
688 |
public void writeRequests(MessageHeader head, |
|
689 |
PosterOutputStream pos) throws IOException { |
|
690 |
requests = head; |
|
691 |
requests.print(serverOutput); |
|
692 |
poster = pos; |
|
693 |
if (poster != null) |
|
694 |
poster.writeTo(serverOutput); |
|
695 |
serverOutput.flush(); |
|
696 |
} |
|
697 |
||
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
698 |
public void writeRequests(MessageHeader head, |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
699 |
PosterOutputStream pos, |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
700 |
boolean streaming) throws IOException { |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
701 |
this.streaming = streaming; |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
702 |
writeRequests(head, pos); |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
703 |
} |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
704 |
|
2 | 705 |
/** Parse the first line of the HTTP request. It usually looks |
31061 | 706 |
something like: {@literal "HTTP/1.0 <number> comment\r\n"}. */ |
2 | 707 |
|
708 |
public boolean parseHTTP(MessageHeader responses, ProgressSource pi, HttpURLConnection httpuc) |
|
709 |
throws IOException { |
|
710 |
/* If "HTTP/*" is found in the beginning, return true. Let |
|
711 |
* HttpURLConnection parse the mime header itself. |
|
712 |
* |
|
713 |
* If this isn't valid HTTP, then we don't try to parse a header |
|
714 |
* out of the beginning of the response into the responses, |
|
715 |
* and instead just queue up the output stream to it's very beginning. |
|
716 |
* This seems most reasonable, and is what the NN browser does. |
|
717 |
*/ |
|
718 |
||
719 |
try { |
|
720 |
serverInput = serverSocket.getInputStream(); |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
721 |
if (capture != null) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
722 |
serverInput = new HttpCaptureInputStream(serverInput, capture); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
723 |
} |
2 | 724 |
serverInput = new BufferedInputStream(serverInput); |
725 |
return (parseHTTPHeader(responses, pi, httpuc)); |
|
726 |
} catch (SocketTimeoutException stex) { |
|
727 |
// We don't want to retry the request when the app. sets a timeout |
|
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
728 |
// but don't close the server if timeout while waiting for 100-continue |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
729 |
if (ignoreContinue) { |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
730 |
closeServer(); |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
731 |
} |
2 | 732 |
throw stex; |
733 |
} catch (IOException e) { |
|
734 |
closeServer(); |
|
735 |
cachedHttpClient = false; |
|
736 |
if (!failedOnce && requests != null) { |
|
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
737 |
failedOnce = true; |
27717
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
738 |
if (getRequestMethod().equals("CONNECT") |
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
739 |
|| streaming |
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
740 |
|| (httpuc.getRequestMethod().equals("POST") |
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
741 |
&& !retryPostProp)) { |
2 | 742 |
// do not retry the request |
743 |
} else { |
|
744 |
// try once more |
|
745 |
openServer(); |
|
746 |
if (needsTunneling()) { |
|
24045
31a23ee57590
8025710: Proxied HTTPS connections reused by HttpClient can send CONNECT to the server
chegar
parents:
21278
diff
changeset
|
747 |
MessageHeader origRequests = requests; |
2 | 748 |
httpuc.doTunneling(); |
24045
31a23ee57590
8025710: Proxied HTTPS connections reused by HttpClient can send CONNECT to the server
chegar
parents:
21278
diff
changeset
|
749 |
requests = origRequests; |
2 | 750 |
} |
751 |
afterConnect(); |
|
752 |
writeRequests(requests, poster); |
|
753 |
return parseHTTP(responses, pi, httpuc); |
|
754 |
} |
|
755 |
} |
|
756 |
throw e; |
|
757 |
} |
|
758 |
||
759 |
} |
|
760 |
||
761 |
private boolean parseHTTPHeader(MessageHeader responses, ProgressSource pi, HttpURLConnection httpuc) |
|
762 |
throws IOException { |
|
763 |
/* If "HTTP/*" is found in the beginning, return true. Let |
|
764 |
* HttpURLConnection parse the mime header itself. |
|
765 |
* |
|
766 |
* If this isn't valid HTTP, then we don't try to parse a header |
|
767 |
* out of the beginning of the response into the responses, |
|
768 |
* and instead just queue up the output stream to it's very beginning. |
|
769 |
* This seems most reasonable, and is what the NN browser does. |
|
770 |
*/ |
|
771 |
||
772 |
keepAliveConnections = -1; |
|
773 |
keepAliveTimeout = 0; |
|
774 |
||
775 |
boolean ret = false; |
|
776 |
byte[] b = new byte[8]; |
|
777 |
||
778 |
try { |
|
779 |
int nread = 0; |
|
780 |
serverInput.mark(10); |
|
781 |
while (nread < 8) { |
|
782 |
int r = serverInput.read(b, nread, 8 - nread); |
|
783 |
if (r < 0) { |
|
784 |
break; |
|
785 |
} |
|
786 |
nread += r; |
|
787 |
} |
|
788 |
String keep=null; |
|
44753 | 789 |
String authenticate=null; |
2 | 790 |
ret = b[0] == 'H' && b[1] == 'T' |
791 |
&& b[2] == 'T' && b[3] == 'P' && b[4] == '/' && |
|
792 |
b[5] == '1' && b[6] == '.'; |
|
793 |
serverInput.reset(); |
|
794 |
if (ret) { // is valid HTTP - response started w/ "HTTP/1." |
|
795 |
responses.parseHeader(serverInput); |
|
796 |
||
797 |
// we've finished parsing http headers |
|
798 |
// check if there are any applicable cookies to set (in cache) |
|
11528
638ca25aec87
7129083: CookieManager does not store cookies if url is read before setting cookie manager
chegar
parents:
10419
diff
changeset
|
799 |
CookieHandler cookieHandler = httpuc.getCookieHandler(); |
2 | 800 |
if (cookieHandler != null) { |
801 |
URI uri = ParseUtil.toURI(url); |
|
802 |
// NOTE: That cast from Map shouldn't be necessary but |
|
803 |
// a bug in javac is triggered under certain circumstances |
|
804 |
// So we do put the cast in as a workaround until |
|
805 |
// it is resolved. |
|
806 |
if (uri != null) |
|
51 | 807 |
cookieHandler.put(uri, responses.getHeaders()); |
2 | 808 |
} |
809 |
||
810 |
/* decide if we're keeping alive: |
|
811 |
* This is a bit tricky. There's a spec, but most current |
|
812 |
* servers (10/1/96) that support this differ in dialects. |
|
813 |
* If the server/client misunderstand each other, the |
|
814 |
* protocol should fall back onto HTTP/1.0, no keep-alive. |
|
815 |
*/ |
|
816 |
if (usingProxy) { // not likely a proxy will return this |
|
817 |
keep = responses.findValue("Proxy-Connection"); |
|
44753 | 818 |
authenticate = responses.findValue("Proxy-Authenticate"); |
2 | 819 |
} |
820 |
if (keep == null) { |
|
821 |
keep = responses.findValue("Connection"); |
|
44753 | 822 |
authenticate = responses.findValue("WWW-Authenticate"); |
2 | 823 |
} |
44753 | 824 |
|
825 |
// 'disableKeepAlive' starts with the value false. |
|
826 |
// It can transition from false to true, but once true |
|
827 |
// it stays true. |
|
828 |
// If cacheNTLMProp is false, and disableKeepAlive is false, |
|
829 |
// then we need to examine the response headers to figure out |
|
830 |
// whether we are doing NTLM authentication. If we do NTLM, |
|
831 |
// and cacheNTLMProp is false, than we can't keep this connection |
|
832 |
// alive: we will switch disableKeepAlive to true. |
|
833 |
boolean canKeepAlive = !disableKeepAlive; |
|
44755 | 834 |
if (canKeepAlive && (cacheNTLMProp == false || cacheSPNEGOProp == false) |
835 |
&& authenticate != null) { |
|
44753 | 836 |
authenticate = authenticate.toLowerCase(Locale.US); |
44755 | 837 |
if (cacheNTLMProp == false) { |
838 |
canKeepAlive &= !authenticate.startsWith("ntlm "); |
|
839 |
} |
|
840 |
if (cacheSPNEGOProp == false) { |
|
841 |
canKeepAlive &= !authenticate.startsWith("negotiate "); |
|
842 |
canKeepAlive &= !authenticate.startsWith("kerberos "); |
|
843 |
} |
|
44753 | 844 |
} |
845 |
disableKeepAlive |= !canKeepAlive; |
|
846 |
||
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
847 |
if (keep != null && keep.toLowerCase(Locale.US).equals("keep-alive")) { |
2 | 848 |
/* some servers, notably Apache1.1, send something like: |
849 |
* "Keep-Alive: timeout=15, max=1" which we should respect. |
|
850 |
*/ |
|
44753 | 851 |
if (disableKeepAlive) { |
852 |
keepAliveConnections = 1; |
|
853 |
} else { |
|
854 |
HeaderParser p = new HeaderParser( |
|
2 | 855 |
responses.findValue("Keep-Alive")); |
856 |
/* default should be larger in case of proxy */ |
|
857 |
keepAliveConnections = p.findInt("max", usingProxy?50:5); |
|
858 |
keepAliveTimeout = p.findInt("timeout", usingProxy?60:5); |
|
859 |
} |
|
860 |
} else if (b[7] != '0') { |
|
861 |
/* |
|
862 |
* We're talking 1.1 or later. Keep persistent until |
|
863 |
* the server says to close. |
|
864 |
*/ |
|
44753 | 865 |
if (keep != null || disableKeepAlive) { |
2 | 866 |
/* |
867 |
* The only Connection token we understand is close. |
|
868 |
* Paranoia: if there is any Connection header then |
|
869 |
* treat as non-persistent. |
|
870 |
*/ |
|
871 |
keepAliveConnections = 1; |
|
872 |
} else { |
|
873 |
keepAliveConnections = 5; |
|
874 |
} |
|
875 |
} |
|
876 |
} else if (nread != 8) { |
|
877 |
if (!failedOnce && requests != null) { |
|
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
878 |
failedOnce = true; |
27717
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
879 |
if (getRequestMethod().equals("CONNECT") |
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
880 |
|| streaming |
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
881 |
|| (httpuc.getRequestMethod().equals("POST") |
9d29bef916e1
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
chegar
parents:
26720
diff
changeset
|
882 |
&& !retryPostProp)) { |
2 | 883 |
// do not retry the request |
884 |
} else { |
|
885 |
closeServer(); |
|
886 |
cachedHttpClient = false; |
|
887 |
openServer(); |
|
888 |
if (needsTunneling()) { |
|
24045
31a23ee57590
8025710: Proxied HTTPS connections reused by HttpClient can send CONNECT to the server
chegar
parents:
21278
diff
changeset
|
889 |
MessageHeader origRequests = requests; |
2 | 890 |
httpuc.doTunneling(); |
24045
31a23ee57590
8025710: Proxied HTTPS connections reused by HttpClient can send CONNECT to the server
chegar
parents:
21278
diff
changeset
|
891 |
requests = origRequests; |
2 | 892 |
} |
893 |
afterConnect(); |
|
894 |
writeRequests(requests, poster); |
|
895 |
return parseHTTP(responses, pi, httpuc); |
|
896 |
} |
|
897 |
} |
|
898 |
throw new SocketException("Unexpected end of file from server"); |
|
899 |
} else { |
|
900 |
// we can't vouche for what this is.... |
|
901 |
responses.set("Content-type", "unknown/unknown"); |
|
902 |
} |
|
903 |
} catch (IOException e) { |
|
904 |
throw e; |
|
905 |
} |
|
906 |
||
907 |
int code = -1; |
|
908 |
try { |
|
909 |
String resp; |
|
910 |
resp = responses.getValue(0); |
|
911 |
/* should have no leading/trailing LWS |
|
912 |
* expedite the typical case by assuming it has |
|
913 |
* form "HTTP/1.x <WS> 2XX <mumble>" |
|
914 |
*/ |
|
915 |
int ind; |
|
916 |
ind = resp.indexOf(' '); |
|
917 |
while(resp.charAt(ind) == ' ') |
|
918 |
ind++; |
|
26720
6b160d97c51d
8055032: Improve numerical parsing in java.net and sun.net
redestad
parents:
25859
diff
changeset
|
919 |
code = Integer.parseInt(resp, ind, ind + 3, 10); |
2 | 920 |
} catch (Exception e) {} |
921 |
||
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
922 |
if (code == HTTP_CONTINUE && ignoreContinue) { |
2 | 923 |
responses.reset(); |
924 |
return parseHTTPHeader(responses, pi, httpuc); |
|
925 |
} |
|
926 |
||
927 |
long cl = -1; |
|
928 |
||
929 |
/* |
|
930 |
* Set things up to parse the entity body of the reply. |
|
931 |
* We should be smarter about avoid pointless work when |
|
932 |
* the HTTP method and response code indicate there will be |
|
933 |
* no entity body to parse. |
|
934 |
*/ |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
935 |
String te = responses.findValue("Transfer-Encoding"); |
2 | 936 |
if (te != null && te.equalsIgnoreCase("chunked")) { |
937 |
serverInput = new ChunkedInputStream(serverInput, this, responses); |
|
938 |
||
939 |
/* |
|
940 |
* If keep alive not specified then close after the stream |
|
941 |
* has completed. |
|
942 |
*/ |
|
943 |
if (keepAliveConnections <= 1) { |
|
944 |
keepAliveConnections = 1; |
|
945 |
keepingAlive = false; |
|
946 |
} else { |
|
44753 | 947 |
keepingAlive = !disableKeepAlive; |
2 | 948 |
} |
949 |
failedOnce = false; |
|
950 |
} else { |
|
951 |
||
952 |
/* |
|
953 |
* If it's a keep alive connection then we will keep |
|
954 |
* (alive if :- |
|
955 |
* 1. content-length is specified, or |
|
956 |
* 2. "Not-Modified" or "No-Content" responses - RFC 2616 states that |
|
957 |
* 204 or 304 response must not include a message body. |
|
958 |
*/ |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
959 |
String cls = responses.findValue("content-length"); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
960 |
if (cls != null) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
961 |
try { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
962 |
cl = Long.parseLong(cls); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
963 |
} catch (NumberFormatException e) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
964 |
cl = -1; |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
965 |
} |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
966 |
} |
2 | 967 |
String requestLine = requests.getKey(0); |
968 |
||
969 |
if ((requestLine != null && |
|
970 |
(requestLine.startsWith("HEAD"))) || |
|
971 |
code == HttpURLConnection.HTTP_NOT_MODIFIED || |
|
972 |
code == HttpURLConnection.HTTP_NO_CONTENT) { |
|
973 |
cl = 0; |
|
974 |
} |
|
975 |
||
976 |
if (keepAliveConnections > 1 && |
|
977 |
(cl >= 0 || |
|
978 |
code == HttpURLConnection.HTTP_NOT_MODIFIED || |
|
979 |
code == HttpURLConnection.HTTP_NO_CONTENT)) { |
|
44753 | 980 |
keepingAlive = !disableKeepAlive; |
2 | 981 |
failedOnce = false; |
982 |
} else if (keepingAlive) { |
|
983 |
/* Previously we were keeping alive, and now we're not. Remove |
|
984 |
* this from the cache (but only here, once) - otherwise we get |
|
985 |
* multiple removes and the cache count gets messed up. |
|
986 |
*/ |
|
987 |
keepingAlive=false; |
|
988 |
} |
|
989 |
} |
|
990 |
||
991 |
/* wrap a KeepAliveStream/MeteredStream around it if appropriate */ |
|
992 |
||
993 |
if (cl > 0) { |
|
994 |
// In this case, content length is well known, so it is okay |
|
995 |
// to wrap the input stream with KeepAliveStream/MeteredStream. |
|
996 |
||
997 |
if (pi != null) { |
|
998 |
// Progress monitor is enabled |
|
999 |
pi.setContentType(responses.findValue("content-type")); |
|
1000 |
} |
|
1001 |
||
44759
b4a251d223e2
8174985: NTLM authentication doesn't work with IIS if NTLM cache is disabled
dfuchs
parents:
44755
diff
changeset
|
1002 |
// If disableKeepAlive == true, the client will not be returned |
b4a251d223e2
8174985: NTLM authentication doesn't work with IIS if NTLM cache is disabled
dfuchs
parents:
44755
diff
changeset
|
1003 |
// to the cache. But we still need to use a keepalive stream to |
b4a251d223e2
8174985: NTLM authentication doesn't work with IIS if NTLM cache is disabled
dfuchs
parents:
44755
diff
changeset
|
1004 |
// allow the multi-message authentication exchange on the connection |
b4a251d223e2
8174985: NTLM authentication doesn't work with IIS if NTLM cache is disabled
dfuchs
parents:
44755
diff
changeset
|
1005 |
boolean useKeepAliveStream = isKeepingAlive() || disableKeepAlive; |
b4a251d223e2
8174985: NTLM authentication doesn't work with IIS if NTLM cache is disabled
dfuchs
parents:
44755
diff
changeset
|
1006 |
if (useKeepAliveStream) { |
2 | 1007 |
// Wrap KeepAliveStream if keep alive is enabled. |
16477
15ee12718efe
8009650: HttpClient available() check throws SocketException when connection has been closed
robm
parents:
14008
diff
changeset
|
1008 |
logFinest("KeepAlive stream used: " + url); |
2 | 1009 |
serverInput = new KeepAliveStream(serverInput, pi, cl, this); |
1010 |
failedOnce = false; |
|
1011 |
} |
|
1012 |
else { |
|
1013 |
serverInput = new MeteredStream(serverInput, pi, cl); |
|
1014 |
} |
|
1015 |
} |
|
1016 |
else if (cl == -1) { |
|
1017 |
// In this case, content length is unknown - the input |
|
1018 |
// stream would simply be a regular InputStream or |
|
1019 |
// ChunkedInputStream. |
|
1020 |
||
1021 |
if (pi != null) { |
|
1022 |
// Progress monitoring is enabled. |
|
1023 |
||
1024 |
pi.setContentType(responses.findValue("content-type")); |
|
1025 |
||
1026 |
// Wrap MeteredStream for tracking indeterministic |
|
1027 |
// progress, even if the input stream is ChunkedInputStream. |
|
1028 |
serverInput = new MeteredStream(serverInput, pi, cl); |
|
1029 |
} |
|
1030 |
else { |
|
1031 |
// Progress monitoring is disabled, and there is no |
|
1032 |
// need to wrap an unknown length input stream. |
|
1033 |
||
1034 |
// ** This is an no-op ** |
|
1035 |
} |
|
1036 |
} |
|
1037 |
else { |
|
1038 |
if (pi != null) |
|
1039 |
pi.finishTracking(); |
|
1040 |
} |
|
1041 |
||
1042 |
return ret; |
|
1043 |
} |
|
1044 |
||
57968 | 1045 |
public InputStream getInputStream() { |
1046 |
clientLock.lock(); |
|
1047 |
try { |
|
1048 |
return serverInput; |
|
1049 |
} finally { |
|
1050 |
clientLock.unlock(); |
|
1051 |
} |
|
2 | 1052 |
} |
1053 |
||
1054 |
public OutputStream getOutputStream() { |
|
1055 |
return serverOutput; |
|
1056 |
} |
|
1057 |
||
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
1058 |
@Override |
2 | 1059 |
public String toString() { |
1060 |
return getClass().getName()+"("+url+")"; |
|
1061 |
} |
|
1062 |
||
1063 |
public final boolean isKeepingAlive() { |
|
1064 |
return getHttpKeepAliveSet() && keepingAlive; |
|
1065 |
} |
|
1066 |
||
1067 |
public void setCacheRequest(CacheRequest cacheRequest) { |
|
1068 |
this.cacheRequest = cacheRequest; |
|
1069 |
} |
|
1070 |
||
1071 |
CacheRequest getCacheRequest() { |
|
1072 |
return cacheRequest; |
|
1073 |
} |
|
1074 |
||
10136
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1075 |
String getRequestMethod() { |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1076 |
if (requests != null) { |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1077 |
String requestLine = requests.getKey(0); |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1078 |
if (requestLine != null) { |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1079 |
return requestLine.split("\\s+")[0]; |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1080 |
} |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1081 |
} |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1082 |
return ""; |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1083 |
} |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
1084 |
|
2 | 1085 |
public void setDoNotRetry(boolean value) { |
1086 |
// failedOnce is used to determine if a request should be retried. |
|
1087 |
failedOnce = value; |
|
1088 |
} |
|
1089 |
||
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
1090 |
public void setIgnoreContinue(boolean value) { |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
1091 |
ignoreContinue = value; |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
1092 |
} |
2 | 1093 |
|
1094 |
/* Use only on connections in error. */ |
|
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
1095 |
@Override |
2 | 1096 |
public void closeServer() { |
1097 |
try { |
|
1098 |
keepingAlive = false; |
|
1099 |
serverSocket.close(); |
|
1100 |
} catch (Exception e) {} |
|
1101 |
} |
|
1102 |
||
1103 |
/** |
|
1104 |
* @return the proxy host being used for this client, or null |
|
1105 |
* if we're not going through a proxy |
|
1106 |
*/ |
|
1107 |
public String getProxyHostUsed() { |
|
1108 |
if (!usingProxy) { |
|
1109 |
return null; |
|
1110 |
} else { |
|
1111 |
return ((InetSocketAddress)proxy.address()).getHostString(); |
|
1112 |
} |
|
1113 |
} |
|
1114 |
||
1115 |
/** |
|
1116 |
* @return the proxy port being used for this client. Meaningless |
|
1117 |
* if getProxyHostUsed() gives null. |
|
1118 |
*/ |
|
1119 |
public int getProxyPortUsed() { |
|
1120 |
if (usingProxy) |
|
1121 |
return ((InetSocketAddress)proxy.address()).getPort(); |
|
1122 |
return -1; |
|
1123 |
} |
|
1124 |
} |