author | sherman |
Tue, 30 Aug 2011 11:53:11 -0700 | |
changeset 10419 | 12c063b39232 |
parent 10136 | af9631156b25 |
child 11528 | 638ca25aec87 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1994, 2010, 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; |
2 | 31 |
import sun.net.NetworkClient; |
32 |
import sun.net.ProgressSource; |
|
33 |
import sun.net.www.MessageHeader; |
|
34 |
import sun.net.www.HeaderParser; |
|
35 |
import sun.net.www.MeteredStream; |
|
36 |
import sun.net.www.ParseUtil; |
|
37 |
import sun.net.www.protocol.http.HttpURLConnection; |
|
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3288
diff
changeset
|
38 |
import sun.util.logging.PlatformLogger; |
2 | 39 |
|
40 |
/** |
|
41 |
* @author Herb Jellinek |
|
42 |
* @author Dave Brown |
|
43 |
*/ |
|
44 |
public class HttpClient extends NetworkClient { |
|
45 |
// whether this httpclient comes from the cache |
|
46 |
protected boolean cachedHttpClient = false; |
|
47 |
||
48 |
private boolean inCache; |
|
49 |
||
50 |
protected CookieHandler cookieHandler; |
|
51 |
||
52 |
// Http requests we send |
|
53 |
MessageHeader requests; |
|
54 |
||
55 |
// Http data we send with the headers |
|
56 |
PosterOutputStream poster = null; |
|
57 |
||
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
58 |
// 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
|
59 |
boolean streaming; |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
60 |
|
2 | 61 |
// if we've had one io error |
62 |
boolean failedOnce = false; |
|
63 |
||
64 |
/** Response code for CONTINUE */ |
|
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
65 |
private boolean ignoreContinue = true; |
2 | 66 |
private static final int HTTP_CONTINUE = 100; |
67 |
||
68 |
/** Default port number for http daemons. REMIND: make these private */ |
|
69 |
static final int httpPortNumber = 80; |
|
70 |
||
71 |
/** return default port number (subclasses may override) */ |
|
72 |
protected int getDefaultPort () { return httpPortNumber; } |
|
73 |
||
74 |
static private int getDefaultPort(String proto) { |
|
75 |
if ("http".equalsIgnoreCase(proto)) |
|
76 |
return 80; |
|
77 |
if ("https".equalsIgnoreCase(proto)) |
|
78 |
return 443; |
|
79 |
return -1; |
|
80 |
} |
|
81 |
||
82 |
/* All proxying (generic as well as instance-specific) may be |
|
83 |
* disabled through use of this flag |
|
84 |
*/ |
|
85 |
protected boolean proxyDisabled; |
|
86 |
||
87 |
// are we using proxy in this instance? |
|
88 |
public boolean usingProxy = false; |
|
89 |
// target host, port for the URL |
|
90 |
protected String host; |
|
91 |
protected int port; |
|
92 |
||
93 |
/* where we cache currently open, persistent connections */ |
|
94 |
protected static KeepAliveCache kac = new KeepAliveCache(); |
|
95 |
||
96 |
private static boolean keepAliveProp = true; |
|
97 |
||
98 |
// retryPostProp is true by default so as to preserve behavior |
|
99 |
// from previous releases. |
|
100 |
private static boolean retryPostProp = true; |
|
101 |
||
102 |
volatile boolean keepingAlive = false; /* this is a keep-alive connection */ |
|
103 |
int keepAliveConnections = -1; /* number of keep-alives left */ |
|
104 |
||
105 |
/**Idle timeout value, in milliseconds. Zero means infinity, |
|
106 |
* iff keepingAlive=true. |
|
107 |
* Unfortunately, we can't always believe this one. If I'm connected |
|
108 |
* through a Netscape proxy to a server that sent me a keep-alive |
|
109 |
* time of 15 sec, the proxy unilaterally terminates my connection |
|
110 |
* after 5 sec. So we have to hard code our effective timeout to |
|
111 |
* 4 sec for the case where we're using a proxy. *SIGH* |
|
112 |
*/ |
|
113 |
int keepAliveTimeout = 0; |
|
114 |
||
115 |
/** whether the response is to be cached */ |
|
116 |
private CacheRequest cacheRequest = null; |
|
117 |
||
118 |
/** Url being fetched. */ |
|
119 |
protected URL url; |
|
120 |
||
121 |
/* if set, the client will be reused and must not be put in cache */ |
|
122 |
public boolean reuse = false; |
|
123 |
||
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
124 |
// Traffic capture tool, if configured. See HttpCapture class for info |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
125 |
private HttpCapture capture = null; |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
126 |
|
2 | 127 |
/** |
128 |
* A NOP method kept for backwards binary compatibility |
|
129 |
* @deprecated -- system properties are no longer cached. |
|
130 |
*/ |
|
131 |
@Deprecated |
|
132 |
public static synchronized void resetProperties() { |
|
133 |
} |
|
134 |
||
135 |
int getKeepAliveTimeout() { |
|
136 |
return keepAliveTimeout; |
|
137 |
} |
|
138 |
||
139 |
static { |
|
140 |
String keepAlive = java.security.AccessController.doPrivileged( |
|
141 |
new sun.security.action.GetPropertyAction("http.keepAlive")); |
|
142 |
||
143 |
String retryPost = java.security.AccessController.doPrivileged( |
|
144 |
new sun.security.action.GetPropertyAction("sun.net.http.retryPost")); |
|
145 |
||
146 |
if (keepAlive != null) { |
|
147 |
keepAliveProp = Boolean.valueOf(keepAlive).booleanValue(); |
|
148 |
} else { |
|
149 |
keepAliveProp = true; |
|
150 |
} |
|
151 |
||
152 |
if (retryPost != null) { |
|
153 |
retryPostProp = Boolean.valueOf(retryPost).booleanValue(); |
|
154 |
} else |
|
155 |
retryPostProp = true; |
|
156 |
||
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
* @return true iff http keep alive is set (i.e. enabled). Defaults |
|
161 |
* to true if the system property http.keepAlive isn't set. |
|
162 |
*/ |
|
163 |
public boolean getHttpKeepAliveSet() { |
|
164 |
return keepAliveProp; |
|
165 |
} |
|
166 |
||
167 |
||
168 |
protected HttpClient() { |
|
169 |
} |
|
170 |
||
171 |
private HttpClient(URL url) |
|
172 |
throws IOException { |
|
173 |
this(url, (String)null, -1, false); |
|
174 |
} |
|
175 |
||
176 |
protected HttpClient(URL url, |
|
177 |
boolean proxyDisabled) throws IOException { |
|
178 |
this(url, null, -1, proxyDisabled); |
|
179 |
} |
|
180 |
||
181 |
/* This package-only CTOR should only be used for FTP piggy-backed on HTTP |
|
182 |
* HTTP URL's that use this won't take advantage of keep-alive. |
|
183 |
* Additionally, this constructor may be used as a last resort when the |
|
184 |
* first HttpClient gotten through New() failed (probably b/c of a |
|
185 |
* Keep-Alive mismatch). |
|
186 |
* |
|
187 |
* XXX That documentation is wrong ... it's not package-private any more |
|
188 |
*/ |
|
189 |
public HttpClient(URL url, String proxyHost, int proxyPort) |
|
190 |
throws IOException { |
|
191 |
this(url, proxyHost, proxyPort, false); |
|
192 |
} |
|
193 |
||
194 |
protected HttpClient(URL url, Proxy p, int to) throws IOException { |
|
195 |
proxy = (p == null) ? Proxy.NO_PROXY : p; |
|
196 |
this.host = url.getHost(); |
|
197 |
this.url = url; |
|
198 |
port = url.getPort(); |
|
199 |
if (port == -1) { |
|
200 |
port = getDefaultPort(); |
|
201 |
} |
|
202 |
setConnectTimeout(to); |
|
203 |
||
204 |
// get the cookieHandler if there is any |
|
51 | 205 |
cookieHandler = java.security.AccessController.doPrivileged( |
206 |
new java.security.PrivilegedAction<CookieHandler>() { |
|
207 |
public CookieHandler run() { |
|
2 | 208 |
return CookieHandler.getDefault(); |
209 |
} |
|
210 |
}); |
|
211 |
||
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
212 |
capture = HttpCapture.getCapture(url); |
2 | 213 |
openServer(); |
214 |
} |
|
215 |
||
216 |
static protected Proxy newHttpProxy(String proxyHost, int proxyPort, |
|
217 |
String proto) { |
|
218 |
if (proxyHost == null || proto == null) |
|
219 |
return Proxy.NO_PROXY; |
|
220 |
int pport = proxyPort < 0 ? getDefaultPort(proto) : proxyPort; |
|
221 |
InetSocketAddress saddr = InetSocketAddress.createUnresolved(proxyHost, pport); |
|
222 |
return new Proxy(Proxy.Type.HTTP, saddr); |
|
223 |
} |
|
224 |
||
225 |
/* |
|
226 |
* This constructor gives "ultimate" flexibility, including the ability |
|
227 |
* to bypass implicit proxying. Sometimes we need to be using tunneling |
|
228 |
* (transport or network level) instead of proxying (application level), |
|
229 |
* for example when we don't want the application level data to become |
|
230 |
* visible to third parties. |
|
231 |
* |
|
232 |
* @param url the URL to which we're connecting |
|
233 |
* @param proxy proxy to use for this URL (e.g. forwarding) |
|
234 |
* @param proxyPort proxy port to use for this URL |
|
235 |
* @param proxyDisabled true to disable default proxying |
|
236 |
*/ |
|
237 |
private HttpClient(URL url, String proxyHost, int proxyPort, |
|
238 |
boolean proxyDisabled) |
|
239 |
throws IOException { |
|
240 |
this(url, proxyDisabled ? Proxy.NO_PROXY : |
|
241 |
newHttpProxy(proxyHost, proxyPort, "http"), -1); |
|
242 |
} |
|
243 |
||
244 |
public HttpClient(URL url, String proxyHost, int proxyPort, |
|
245 |
boolean proxyDisabled, int to) |
|
246 |
throws IOException { |
|
247 |
this(url, proxyDisabled ? Proxy.NO_PROXY : |
|
248 |
newHttpProxy(proxyHost, proxyPort, "http"), to); |
|
249 |
} |
|
250 |
||
251 |
/* This class has no public constructor for HTTP. This method is used to |
|
252 |
* get an HttpClient to the specifed URL. If there's currently an |
|
253 |
* active HttpClient to that server/port, you'll get that one. |
|
254 |
*/ |
|
255 |
public static HttpClient New(URL url) |
|
256 |
throws IOException { |
|
257 |
return HttpClient.New(url, Proxy.NO_PROXY, -1, true); |
|
258 |
} |
|
259 |
||
260 |
public static HttpClient New(URL url, boolean useCache) |
|
261 |
throws IOException { |
|
262 |
return HttpClient.New(url, Proxy.NO_PROXY, -1, useCache); |
|
263 |
} |
|
264 |
||
265 |
public static HttpClient New(URL url, Proxy p, int to, boolean useCache) |
|
266 |
throws IOException { |
|
267 |
if (p == null) { |
|
268 |
p = Proxy.NO_PROXY; |
|
269 |
} |
|
270 |
HttpClient ret = null; |
|
271 |
/* see if one's already around */ |
|
272 |
if (useCache) { |
|
51 | 273 |
ret = kac.get(url, null); |
2 | 274 |
if (ret != null) { |
275 |
if ((ret.proxy != null && ret.proxy.equals(p)) || |
|
276 |
(ret.proxy == null && p == null)) { |
|
277 |
synchronized (ret) { |
|
278 |
ret.cachedHttpClient = true; |
|
279 |
assert ret.inCache; |
|
280 |
ret.inCache = false; |
|
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
281 |
PlatformLogger logger = HttpURLConnection.getHttpLogger(); |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
282 |
if (logger.isLoggable(PlatformLogger.FINEST)) { |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
283 |
logger.finest("KeepAlive stream retrieved from the cache, " + ret); |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
284 |
} |
2 | 285 |
} |
286 |
} else { |
|
287 |
// We cannot return this connection to the cache as it's |
|
288 |
// KeepAliveTimeout will get reset. We simply close the connection. |
|
289 |
// This should be fine as it is very rare that a connection |
|
290 |
// to the same host will not use the same proxy. |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
291 |
synchronized(ret) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
292 |
ret.inCache = false; |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
293 |
ret.closeServer(); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
294 |
} |
2 | 295 |
ret = null; |
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
if (ret == null) { |
|
300 |
ret = new HttpClient(url, p, to); |
|
301 |
} else { |
|
302 |
SecurityManager security = System.getSecurityManager(); |
|
303 |
if (security != null) { |
|
9775 | 304 |
if (ret.proxy == Proxy.NO_PROXY || ret.proxy == null) { |
305 |
security.checkConnect(InetAddress.getByName(url.getHost()).getHostAddress(), url.getPort()); |
|
306 |
} else { |
|
307 |
security.checkConnect(url.getHost(), url.getPort()); |
|
308 |
} |
|
2 | 309 |
} |
310 |
ret.url = url; |
|
311 |
} |
|
312 |
return ret; |
|
313 |
} |
|
314 |
||
315 |
public static HttpClient New(URL url, Proxy p, int to) throws IOException { |
|
316 |
return New(url, p, to, true); |
|
317 |
} |
|
318 |
||
319 |
public static HttpClient New(URL url, String proxyHost, int proxyPort, |
|
320 |
boolean useCache) |
|
321 |
throws IOException { |
|
322 |
return New(url, newHttpProxy(proxyHost, proxyPort, "http"), -1, useCache); |
|
323 |
} |
|
324 |
||
325 |
public static HttpClient New(URL url, String proxyHost, int proxyPort, |
|
326 |
boolean useCache, int to) |
|
327 |
throws IOException { |
|
328 |
return New(url, newHttpProxy(proxyHost, proxyPort, "http"), to, useCache); |
|
329 |
} |
|
330 |
||
331 |
/* return it to the cache as still usable, if: |
|
332 |
* 1) It's keeping alive, AND |
|
333 |
* 2) It still has some connections left, AND |
|
334 |
* 3) It hasn't had a error (PrintStream.checkError()) |
|
335 |
* 4) It hasn't timed out |
|
336 |
* |
|
337 |
* If this client is not keepingAlive, it should have been |
|
338 |
* removed from the cache in the parseHeaders() method. |
|
339 |
*/ |
|
340 |
||
341 |
public void finished() { |
|
342 |
if (reuse) /* will be reused */ |
|
343 |
return; |
|
344 |
keepAliveConnections--; |
|
345 |
poster = null; |
|
346 |
if (keepAliveConnections > 0 && isKeepingAlive() && |
|
347 |
!(serverOutput.checkError())) { |
|
348 |
/* This connection is keepingAlive && still valid. |
|
349 |
* Return it to the cache. |
|
350 |
*/ |
|
351 |
putInKeepAliveCache(); |
|
352 |
} else { |
|
353 |
closeServer(); |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
protected synchronized void putInKeepAliveCache() { |
|
358 |
if (inCache) { |
|
359 |
assert false : "Duplicate put to keep alive cache"; |
|
360 |
return; |
|
361 |
} |
|
362 |
inCache = true; |
|
363 |
kac.put(url, null, this); |
|
364 |
} |
|
365 |
||
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
366 |
protected synchronized boolean isInKeepAliveCache() { |
2 | 367 |
return inCache; |
368 |
} |
|
369 |
||
370 |
/* |
|
371 |
* Close an idle connection to this URL (if it exists in the |
|
372 |
* cache). |
|
373 |
*/ |
|
374 |
public void closeIdleConnection() { |
|
51 | 375 |
HttpClient http = kac.get(url, null); |
2 | 376 |
if (http != null) { |
377 |
http.closeServer(); |
|
378 |
} |
|
379 |
} |
|
380 |
||
381 |
/* We're very particular here about what our InputStream to the server |
|
382 |
* looks like for reasons that are apparent if you can decipher the |
|
383 |
* method parseHTTP(). That's why this method is overidden from the |
|
384 |
* superclass. |
|
385 |
*/ |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
386 |
@Override |
2 | 387 |
public void openServer(String server, int port) throws IOException { |
388 |
serverSocket = doConnect(server, port); |
|
389 |
try { |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
390 |
OutputStream out = serverSocket.getOutputStream(); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
391 |
if (capture != null) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
392 |
out = new HttpCaptureOutputStream(out, capture); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
393 |
} |
2 | 394 |
serverOutput = new PrintStream( |
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
395 |
new BufferedOutputStream(out), |
2 | 396 |
false, encoding); |
397 |
} catch (UnsupportedEncodingException e) { |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
10136
diff
changeset
|
398 |
throw new InternalError(encoding+" encoding not found", e); |
2 | 399 |
} |
400 |
serverSocket.setTcpNoDelay(true); |
|
401 |
} |
|
402 |
||
403 |
/* |
|
404 |
* Returns true if the http request should be tunneled through proxy. |
|
405 |
* An example where this is the case is Https. |
|
406 |
*/ |
|
407 |
public boolean needsTunneling() { |
|
408 |
return false; |
|
409 |
} |
|
410 |
||
411 |
/* |
|
412 |
* Returns true if this httpclient is from cache |
|
413 |
*/ |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
414 |
public synchronized boolean isCachedConnection() { |
2 | 415 |
return cachedHttpClient; |
416 |
} |
|
417 |
||
418 |
/* |
|
419 |
* Finish any work left after the socket connection is |
|
420 |
* established. In the normal http case, it's a NO-OP. Subclass |
|
421 |
* may need to override this. An example is Https, where for |
|
422 |
* direct connection to the origin server, ssl handshake needs to |
|
423 |
* be done; for proxy tunneling, the socket needs to be converted |
|
424 |
* into an SSL socket before ssl handshake can take place. |
|
425 |
*/ |
|
426 |
public void afterConnect() throws IOException, UnknownHostException { |
|
427 |
// NO-OP. Needs to be overwritten by HttpsClient |
|
428 |
} |
|
429 |
||
430 |
/* |
|
431 |
* call openServer in a privileged block |
|
432 |
*/ |
|
433 |
private synchronized void privilegedOpenServer(final InetSocketAddress server) |
|
434 |
throws IOException |
|
435 |
{ |
|
436 |
try { |
|
437 |
java.security.AccessController.doPrivileged( |
|
51 | 438 |
new java.security.PrivilegedExceptionAction<Void>() { |
439 |
public Void run() throws IOException { |
|
2 | 440 |
openServer(server.getHostString(), server.getPort()); |
441 |
return null; |
|
442 |
} |
|
443 |
}); |
|
444 |
} catch (java.security.PrivilegedActionException pae) { |
|
445 |
throw (IOException) pae.getException(); |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
/* |
|
450 |
* call super.openServer |
|
451 |
*/ |
|
452 |
private void superOpenServer(final String proxyHost, |
|
453 |
final int proxyPort) |
|
454 |
throws IOException, UnknownHostException |
|
455 |
{ |
|
456 |
super.openServer(proxyHost, proxyPort); |
|
457 |
} |
|
458 |
||
459 |
/* |
|
460 |
*/ |
|
461 |
protected synchronized void openServer() throws IOException { |
|
462 |
||
463 |
SecurityManager security = System.getSecurityManager(); |
|
9775 | 464 |
|
9550
c3a275ce56d3
7041044: InetAddress.getByName(String,InetAddress) added in error
michaelm
parents:
9544
diff
changeset
|
465 |
if (security != null) { |
c3a275ce56d3
7041044: InetAddress.getByName(String,InetAddress) added in error
michaelm
parents:
9544
diff
changeset
|
466 |
security.checkConnect(host, port); |
c3a275ce56d3
7041044: InetAddress.getByName(String,InetAddress) added in error
michaelm
parents:
9544
diff
changeset
|
467 |
} |
2 | 468 |
|
469 |
if (keepingAlive) { // already opened |
|
470 |
return; |
|
471 |
} |
|
472 |
||
473 |
if (url.getProtocol().equals("http") || |
|
474 |
url.getProtocol().equals("https") ) { |
|
475 |
||
476 |
if ((proxy != null) && (proxy.type() == Proxy.Type.HTTP)) { |
|
9775 | 477 |
sun.net.www.URLConnection.setProxiedHost(host); |
2 | 478 |
privilegedOpenServer((InetSocketAddress) proxy.address()); |
479 |
usingProxy = true; |
|
480 |
return; |
|
481 |
} else { |
|
482 |
// make direct connection |
|
483 |
openServer(host, port); |
|
484 |
usingProxy = false; |
|
485 |
return; |
|
486 |
} |
|
487 |
||
488 |
} else { |
|
489 |
/* we're opening some other kind of url, most likely an |
|
490 |
* ftp url. |
|
491 |
*/ |
|
492 |
if ((proxy != null) && (proxy.type() == Proxy.Type.HTTP)) { |
|
9775 | 493 |
sun.net.www.URLConnection.setProxiedHost(host); |
2 | 494 |
privilegedOpenServer((InetSocketAddress) proxy.address()); |
495 |
usingProxy = true; |
|
496 |
return; |
|
497 |
} else { |
|
498 |
// make direct connection |
|
499 |
super.openServer(host, port); |
|
500 |
usingProxy = false; |
|
501 |
return; |
|
502 |
} |
|
503 |
} |
|
504 |
} |
|
505 |
||
506 |
public String getURLFile() throws IOException { |
|
507 |
||
508 |
String fileName = url.getFile(); |
|
509 |
if ((fileName == null) || (fileName.length() == 0)) |
|
510 |
fileName = "/"; |
|
511 |
||
512 |
/** |
|
513 |
* proxyDisabled is set by subclass HttpsClient! |
|
514 |
*/ |
|
515 |
if (usingProxy && !proxyDisabled) { |
|
516 |
// Do not use URLStreamHandler.toExternalForm as the fragment |
|
517 |
// should not be part of the RequestURI. It should be an |
|
518 |
// absolute URI which does not have a fragment part. |
|
519 |
StringBuffer result = new StringBuffer(128); |
|
520 |
result.append(url.getProtocol()); |
|
521 |
result.append(":"); |
|
522 |
if (url.getAuthority() != null && url.getAuthority().length() > 0) { |
|
523 |
result.append("//"); |
|
524 |
result.append(url.getAuthority()); |
|
525 |
} |
|
526 |
if (url.getPath() != null) { |
|
527 |
result.append(url.getPath()); |
|
528 |
} |
|
529 |
if (url.getQuery() != null) { |
|
530 |
result.append('?'); |
|
531 |
result.append(url.getQuery()); |
|
532 |
} |
|
533 |
||
534 |
fileName = result.toString(); |
|
535 |
} |
|
536 |
if (fileName.indexOf('\n') == -1) |
|
537 |
return fileName; |
|
538 |
else |
|
539 |
throw new java.net.MalformedURLException("Illegal character in URL"); |
|
540 |
} |
|
541 |
||
542 |
/** |
|
543 |
* @deprecated |
|
544 |
*/ |
|
545 |
@Deprecated |
|
546 |
public void writeRequests(MessageHeader head) { |
|
547 |
requests = head; |
|
548 |
requests.print(serverOutput); |
|
549 |
serverOutput.flush(); |
|
550 |
} |
|
551 |
||
552 |
public void writeRequests(MessageHeader head, |
|
553 |
PosterOutputStream pos) throws IOException { |
|
554 |
requests = head; |
|
555 |
requests.print(serverOutput); |
|
556 |
poster = pos; |
|
557 |
if (poster != null) |
|
558 |
poster.writeTo(serverOutput); |
|
559 |
serverOutput.flush(); |
|
560 |
} |
|
561 |
||
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
562 |
public void writeRequests(MessageHeader head, |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
563 |
PosterOutputStream pos, |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
564 |
boolean streaming) throws IOException { |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
565 |
this.streaming = streaming; |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
566 |
writeRequests(head, pos); |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
567 |
} |
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
568 |
|
2 | 569 |
/** Parse the first line of the HTTP request. It usually looks |
570 |
something like: "HTTP/1.0 <number> comment\r\n". */ |
|
571 |
||
572 |
public boolean parseHTTP(MessageHeader responses, ProgressSource pi, HttpURLConnection httpuc) |
|
573 |
throws IOException { |
|
574 |
/* If "HTTP/*" is found in the beginning, return true. Let |
|
575 |
* HttpURLConnection parse the mime header itself. |
|
576 |
* |
|
577 |
* If this isn't valid HTTP, then we don't try to parse a header |
|
578 |
* out of the beginning of the response into the responses, |
|
579 |
* and instead just queue up the output stream to it's very beginning. |
|
580 |
* This seems most reasonable, and is what the NN browser does. |
|
581 |
*/ |
|
582 |
||
583 |
try { |
|
584 |
serverInput = serverSocket.getInputStream(); |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
585 |
if (capture != null) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
586 |
serverInput = new HttpCaptureInputStream(serverInput, capture); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
587 |
} |
2 | 588 |
serverInput = new BufferedInputStream(serverInput); |
589 |
return (parseHTTPHeader(responses, pi, httpuc)); |
|
590 |
} catch (SocketTimeoutException stex) { |
|
591 |
// 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
|
592 |
// 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
|
593 |
if (ignoreContinue) { |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
594 |
closeServer(); |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
595 |
} |
2 | 596 |
throw stex; |
597 |
} catch (IOException e) { |
|
598 |
closeServer(); |
|
599 |
cachedHttpClient = false; |
|
600 |
if (!failedOnce && requests != null) { |
|
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
601 |
failedOnce = true; |
10136
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
602 |
if (getRequestMethod().equals("CONNECT") || |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
603 |
(httpuc.getRequestMethod().equals("POST") && |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
604 |
(!retryPostProp || streaming))) { |
2 | 605 |
// do not retry the request |
606 |
} else { |
|
607 |
// try once more |
|
608 |
openServer(); |
|
609 |
if (needsTunneling()) { |
|
610 |
httpuc.doTunneling(); |
|
611 |
} |
|
612 |
afterConnect(); |
|
613 |
writeRequests(requests, poster); |
|
614 |
return parseHTTP(responses, pi, httpuc); |
|
615 |
} |
|
616 |
} |
|
617 |
throw e; |
|
618 |
} |
|
619 |
||
620 |
} |
|
621 |
||
622 |
private boolean parseHTTPHeader(MessageHeader responses, ProgressSource pi, HttpURLConnection httpuc) |
|
623 |
throws IOException { |
|
624 |
/* If "HTTP/*" is found in the beginning, return true. Let |
|
625 |
* HttpURLConnection parse the mime header itself. |
|
626 |
* |
|
627 |
* If this isn't valid HTTP, then we don't try to parse a header |
|
628 |
* out of the beginning of the response into the responses, |
|
629 |
* and instead just queue up the output stream to it's very beginning. |
|
630 |
* This seems most reasonable, and is what the NN browser does. |
|
631 |
*/ |
|
632 |
||
633 |
keepAliveConnections = -1; |
|
634 |
keepAliveTimeout = 0; |
|
635 |
||
636 |
boolean ret = false; |
|
637 |
byte[] b = new byte[8]; |
|
638 |
||
639 |
try { |
|
640 |
int nread = 0; |
|
641 |
serverInput.mark(10); |
|
642 |
while (nread < 8) { |
|
643 |
int r = serverInput.read(b, nread, 8 - nread); |
|
644 |
if (r < 0) { |
|
645 |
break; |
|
646 |
} |
|
647 |
nread += r; |
|
648 |
} |
|
649 |
String keep=null; |
|
650 |
ret = b[0] == 'H' && b[1] == 'T' |
|
651 |
&& b[2] == 'T' && b[3] == 'P' && b[4] == '/' && |
|
652 |
b[5] == '1' && b[6] == '.'; |
|
653 |
serverInput.reset(); |
|
654 |
if (ret) { // is valid HTTP - response started w/ "HTTP/1." |
|
655 |
responses.parseHeader(serverInput); |
|
656 |
||
657 |
// we've finished parsing http headers |
|
658 |
// check if there are any applicable cookies to set (in cache) |
|
659 |
if (cookieHandler != null) { |
|
660 |
URI uri = ParseUtil.toURI(url); |
|
661 |
// NOTE: That cast from Map shouldn't be necessary but |
|
662 |
// a bug in javac is triggered under certain circumstances |
|
663 |
// So we do put the cast in as a workaround until |
|
664 |
// it is resolved. |
|
665 |
if (uri != null) |
|
51 | 666 |
cookieHandler.put(uri, responses.getHeaders()); |
2 | 667 |
} |
668 |
||
669 |
/* decide if we're keeping alive: |
|
670 |
* This is a bit tricky. There's a spec, but most current |
|
671 |
* servers (10/1/96) that support this differ in dialects. |
|
672 |
* If the server/client misunderstand each other, the |
|
673 |
* protocol should fall back onto HTTP/1.0, no keep-alive. |
|
674 |
*/ |
|
675 |
if (usingProxy) { // not likely a proxy will return this |
|
676 |
keep = responses.findValue("Proxy-Connection"); |
|
677 |
} |
|
678 |
if (keep == null) { |
|
679 |
keep = responses.findValue("Connection"); |
|
680 |
} |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
681 |
if (keep != null && keep.toLowerCase(Locale.US).equals("keep-alive")) { |
2 | 682 |
/* some servers, notably Apache1.1, send something like: |
683 |
* "Keep-Alive: timeout=15, max=1" which we should respect. |
|
684 |
*/ |
|
685 |
HeaderParser p = new HeaderParser( |
|
686 |
responses.findValue("Keep-Alive")); |
|
687 |
if (p != null) { |
|
688 |
/* default should be larger in case of proxy */ |
|
689 |
keepAliveConnections = p.findInt("max", usingProxy?50:5); |
|
690 |
keepAliveTimeout = p.findInt("timeout", usingProxy?60:5); |
|
691 |
} |
|
692 |
} else if (b[7] != '0') { |
|
693 |
/* |
|
694 |
* We're talking 1.1 or later. Keep persistent until |
|
695 |
* the server says to close. |
|
696 |
*/ |
|
697 |
if (keep != null) { |
|
698 |
/* |
|
699 |
* The only Connection token we understand is close. |
|
700 |
* Paranoia: if there is any Connection header then |
|
701 |
* treat as non-persistent. |
|
702 |
*/ |
|
703 |
keepAliveConnections = 1; |
|
704 |
} else { |
|
705 |
keepAliveConnections = 5; |
|
706 |
} |
|
707 |
} |
|
708 |
} else if (nread != 8) { |
|
709 |
if (!failedOnce && requests != null) { |
|
6673
3674dbc66612
6672144: HttpURLConnection.getInputStream sends POST request after failed chunked
chegar
parents:
5506
diff
changeset
|
710 |
failedOnce = true; |
10136
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
711 |
if (getRequestMethod().equals("CONNECT") || |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
712 |
(httpuc.getRequestMethod().equals("POST") && |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
713 |
(!retryPostProp || streaming))) { |
2 | 714 |
// do not retry the request |
715 |
} else { |
|
716 |
closeServer(); |
|
717 |
cachedHttpClient = false; |
|
718 |
openServer(); |
|
719 |
if (needsTunneling()) { |
|
720 |
httpuc.doTunneling(); |
|
721 |
} |
|
722 |
afterConnect(); |
|
723 |
writeRequests(requests, poster); |
|
724 |
return parseHTTP(responses, pi, httpuc); |
|
725 |
} |
|
726 |
} |
|
727 |
throw new SocketException("Unexpected end of file from server"); |
|
728 |
} else { |
|
729 |
// we can't vouche for what this is.... |
|
730 |
responses.set("Content-type", "unknown/unknown"); |
|
731 |
} |
|
732 |
} catch (IOException e) { |
|
733 |
throw e; |
|
734 |
} |
|
735 |
||
736 |
int code = -1; |
|
737 |
try { |
|
738 |
String resp; |
|
739 |
resp = responses.getValue(0); |
|
740 |
/* should have no leading/trailing LWS |
|
741 |
* expedite the typical case by assuming it has |
|
742 |
* form "HTTP/1.x <WS> 2XX <mumble>" |
|
743 |
*/ |
|
744 |
int ind; |
|
745 |
ind = resp.indexOf(' '); |
|
746 |
while(resp.charAt(ind) == ' ') |
|
747 |
ind++; |
|
748 |
code = Integer.parseInt(resp.substring(ind, ind + 3)); |
|
749 |
} catch (Exception e) {} |
|
750 |
||
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
751 |
if (code == HTTP_CONTINUE && ignoreContinue) { |
2 | 752 |
responses.reset(); |
753 |
return parseHTTPHeader(responses, pi, httpuc); |
|
754 |
} |
|
755 |
||
756 |
long cl = -1; |
|
757 |
||
758 |
/* |
|
759 |
* Set things up to parse the entity body of the reply. |
|
760 |
* We should be smarter about avoid pointless work when |
|
761 |
* the HTTP method and response code indicate there will be |
|
762 |
* no entity body to parse. |
|
763 |
*/ |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
764 |
String te = responses.findValue("Transfer-Encoding"); |
2 | 765 |
if (te != null && te.equalsIgnoreCase("chunked")) { |
766 |
serverInput = new ChunkedInputStream(serverInput, this, responses); |
|
767 |
||
768 |
/* |
|
769 |
* If keep alive not specified then close after the stream |
|
770 |
* has completed. |
|
771 |
*/ |
|
772 |
if (keepAliveConnections <= 1) { |
|
773 |
keepAliveConnections = 1; |
|
774 |
keepingAlive = false; |
|
775 |
} else { |
|
776 |
keepingAlive = true; |
|
777 |
} |
|
778 |
failedOnce = false; |
|
779 |
} else { |
|
780 |
||
781 |
/* |
|
782 |
* If it's a keep alive connection then we will keep |
|
783 |
* (alive if :- |
|
784 |
* 1. content-length is specified, or |
|
785 |
* 2. "Not-Modified" or "No-Content" responses - RFC 2616 states that |
|
786 |
* 204 or 304 response must not include a message body. |
|
787 |
*/ |
|
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
788 |
String cls = responses.findValue("content-length"); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
789 |
if (cls != null) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
790 |
try { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
791 |
cl = Long.parseLong(cls); |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
792 |
} catch (NumberFormatException e) { |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
793 |
cl = -1; |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
794 |
} |
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
795 |
} |
2 | 796 |
String requestLine = requests.getKey(0); |
797 |
||
798 |
if ((requestLine != null && |
|
799 |
(requestLine.startsWith("HEAD"))) || |
|
800 |
code == HttpURLConnection.HTTP_NOT_MODIFIED || |
|
801 |
code == HttpURLConnection.HTTP_NO_CONTENT) { |
|
802 |
cl = 0; |
|
803 |
} |
|
804 |
||
805 |
if (keepAliveConnections > 1 && |
|
806 |
(cl >= 0 || |
|
807 |
code == HttpURLConnection.HTTP_NOT_MODIFIED || |
|
808 |
code == HttpURLConnection.HTTP_NO_CONTENT)) { |
|
809 |
keepingAlive = true; |
|
810 |
failedOnce = false; |
|
811 |
} else if (keepingAlive) { |
|
812 |
/* Previously we were keeping alive, and now we're not. Remove |
|
813 |
* this from the cache (but only here, once) - otherwise we get |
|
814 |
* multiple removes and the cache count gets messed up. |
|
815 |
*/ |
|
816 |
keepingAlive=false; |
|
817 |
} |
|
818 |
} |
|
819 |
||
820 |
/* wrap a KeepAliveStream/MeteredStream around it if appropriate */ |
|
821 |
||
822 |
if (cl > 0) { |
|
823 |
// In this case, content length is well known, so it is okay |
|
824 |
// to wrap the input stream with KeepAliveStream/MeteredStream. |
|
825 |
||
826 |
if (pi != null) { |
|
827 |
// Progress monitor is enabled |
|
828 |
pi.setContentType(responses.findValue("content-type")); |
|
829 |
} |
|
830 |
||
831 |
if (isKeepingAlive()) { |
|
832 |
// Wrap KeepAliveStream if keep alive is enabled. |
|
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3288
diff
changeset
|
833 |
PlatformLogger logger = HttpURLConnection.getHttpLogger(); |
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3288
diff
changeset
|
834 |
if (logger.isLoggable(PlatformLogger.FINEST)) { |
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3288
diff
changeset
|
835 |
logger.finest("KeepAlive stream used: " + url); |
3059
2975ff687a6b
6811297: Add more logging to HTTP protocol handler
jccollet
parents:
2928
diff
changeset
|
836 |
} |
2 | 837 |
serverInput = new KeepAliveStream(serverInput, pi, cl, this); |
838 |
failedOnce = false; |
|
839 |
} |
|
840 |
else { |
|
841 |
serverInput = new MeteredStream(serverInput, pi, cl); |
|
842 |
} |
|
843 |
} |
|
844 |
else if (cl == -1) { |
|
845 |
// In this case, content length is unknown - the input |
|
846 |
// stream would simply be a regular InputStream or |
|
847 |
// ChunkedInputStream. |
|
848 |
||
849 |
if (pi != null) { |
|
850 |
// Progress monitoring is enabled. |
|
851 |
||
852 |
pi.setContentType(responses.findValue("content-type")); |
|
853 |
||
854 |
// Wrap MeteredStream for tracking indeterministic |
|
855 |
// progress, even if the input stream is ChunkedInputStream. |
|
856 |
serverInput = new MeteredStream(serverInput, pi, cl); |
|
857 |
} |
|
858 |
else { |
|
859 |
// Progress monitoring is disabled, and there is no |
|
860 |
// need to wrap an unknown length input stream. |
|
861 |
||
862 |
// ** This is an no-op ** |
|
863 |
} |
|
864 |
} |
|
865 |
else { |
|
866 |
if (pi != null) |
|
867 |
pi.finishTracking(); |
|
868 |
} |
|
869 |
||
870 |
return ret; |
|
871 |
} |
|
872 |
||
873 |
public synchronized InputStream getInputStream() { |
|
874 |
return serverInput; |
|
875 |
} |
|
876 |
||
877 |
public OutputStream getOutputStream() { |
|
878 |
return serverOutput; |
|
879 |
} |
|
880 |
||
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
881 |
@Override |
2 | 882 |
public String toString() { |
883 |
return getClass().getName()+"("+url+")"; |
|
884 |
} |
|
885 |
||
886 |
public final boolean isKeepingAlive() { |
|
887 |
return getHttpKeepAliveSet() && keepingAlive; |
|
888 |
} |
|
889 |
||
890 |
public void setCacheRequest(CacheRequest cacheRequest) { |
|
891 |
this.cacheRequest = cacheRequest; |
|
892 |
} |
|
893 |
||
894 |
CacheRequest getCacheRequest() { |
|
895 |
return cacheRequest; |
|
896 |
} |
|
897 |
||
10136
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
898 |
String getRequestMethod() { |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
899 |
if (requests != null) { |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
900 |
String requestLine = requests.getKey(0); |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
901 |
if (requestLine != null) { |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
902 |
return requestLine.split("\\s+")[0]; |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
903 |
} |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
904 |
} |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
905 |
return ""; |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
906 |
} |
af9631156b25
6670868: StackOverFlow with bad authenticated Proxy tunnels
chegar
parents:
9775
diff
changeset
|
907 |
|
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
908 |
@Override |
2 | 909 |
protected void finalize() throws Throwable { |
910 |
// This should do nothing. The stream finalizer will |
|
911 |
// close the fd. |
|
912 |
} |
|
913 |
||
914 |
public void setDoNotRetry(boolean value) { |
|
915 |
// failedOnce is used to determine if a request should be retried. |
|
916 |
failedOnce = value; |
|
917 |
} |
|
918 |
||
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
919 |
public void setIgnoreContinue(boolean value) { |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
920 |
ignoreContinue = value; |
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
921 |
} |
2 | 922 |
|
923 |
/* Use only on connections in error. */ |
|
2928
80b0b6c2d527
6726695: HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
jccollet
parents:
715
diff
changeset
|
924 |
@Override |
2 | 925 |
public void closeServer() { |
926 |
try { |
|
927 |
keepingAlive = false; |
|
928 |
serverSocket.close(); |
|
929 |
} catch (Exception e) {} |
|
930 |
} |
|
931 |
||
932 |
/** |
|
933 |
* @return the proxy host being used for this client, or null |
|
934 |
* if we're not going through a proxy |
|
935 |
*/ |
|
936 |
public String getProxyHostUsed() { |
|
937 |
if (!usingProxy) { |
|
938 |
return null; |
|
939 |
} else { |
|
940 |
return ((InetSocketAddress)proxy.address()).getHostString(); |
|
941 |
} |
|
942 |
} |
|
943 |
||
944 |
/** |
|
945 |
* @return the proxy port being used for this client. Meaningless |
|
946 |
* if getProxyHostUsed() gives null. |
|
947 |
*/ |
|
948 |
public int getProxyPortUsed() { |
|
949 |
if (usingProxy) |
|
950 |
return ((InetSocketAddress)proxy.address()).getPort(); |
|
951 |
return -1; |
|
952 |
} |
|
953 |
} |