author | chegar |
Wed, 16 Apr 2008 14:17:54 +0100 | |
changeset 479 | c6ddcfc7ff4d |
parent 478 | 5adf3e3f1ff3 |
child 715 | f16baef3a20e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.net.www.protocol.http; |
|
27 |
||
28 |
import java.net.URL; |
|
29 |
import java.net.URLConnection; |
|
30 |
import java.net.ProtocolException; |
|
31 |
import java.net.HttpRetryException; |
|
32 |
import java.net.PasswordAuthentication; |
|
33 |
import java.net.Authenticator; |
|
34 |
import java.net.InetAddress; |
|
35 |
import java.net.UnknownHostException; |
|
36 |
import java.net.SocketTimeoutException; |
|
37 |
import java.net.Proxy; |
|
38 |
import java.net.ProxySelector; |
|
39 |
import java.net.URI; |
|
40 |
import java.net.InetSocketAddress; |
|
41 |
import java.net.CookieHandler; |
|
42 |
import java.net.ResponseCache; |
|
43 |
import java.net.CacheResponse; |
|
44 |
import java.net.SecureCacheResponse; |
|
45 |
import java.net.CacheRequest; |
|
46 |
import java.net.Authenticator.RequestorType; |
|
47 |
import java.io.*; |
|
48 |
import java.util.Date; |
|
49 |
import java.util.Map; |
|
50 |
import java.util.List; |
|
51 |
import java.util.Locale; |
|
52 |
import java.util.StringTokenizer; |
|
53 |
import java.util.Iterator; |
|
54 |
import java.util.Set; |
|
55 |
import java.util.logging.Level; |
|
56 |
import java.util.logging.Logger; |
|
57 |
import sun.net.*; |
|
58 |
import sun.net.www.*; |
|
59 |
import sun.net.www.http.HttpClient; |
|
60 |
import sun.net.www.http.PosterOutputStream; |
|
61 |
import sun.net.www.http.ChunkedInputStream; |
|
62 |
import sun.net.www.http.ChunkedOutputStream; |
|
63 |
import java.text.SimpleDateFormat; |
|
64 |
import java.util.TimeZone; |
|
65 |
import java.net.MalformedURLException; |
|
66 |
import java.nio.ByteBuffer; |
|
67 |
import java.lang.reflect.*; |
|
68 |
||
69 |
/** |
|
70 |
* A class to represent an HTTP connection to a remote object. |
|
71 |
*/ |
|
72 |
||
73 |
||
74 |
public class HttpURLConnection extends java.net.HttpURLConnection { |
|
75 |
||
76 |
private static Logger logger = Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection"); |
|
77 |
||
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
78 |
static String HTTP_CONNECT = "CONNECT"; |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
79 |
|
2 | 80 |
static final String version; |
81 |
public static final String userAgent; |
|
82 |
||
83 |
/* max # of allowed re-directs */ |
|
84 |
static final int defaultmaxRedirects = 20; |
|
85 |
static final int maxRedirects; |
|
86 |
||
87 |
/* Not all servers support the (Proxy)-Authentication-Info headers. |
|
88 |
* By default, we don't require them to be sent |
|
89 |
*/ |
|
90 |
static final boolean validateProxy; |
|
91 |
static final boolean validateServer; |
|
92 |
||
93 |
private StreamingOutputStream strOutputStream; |
|
94 |
private final static String RETRY_MSG1 = |
|
95 |
"cannot retry due to proxy authentication, in streaming mode"; |
|
96 |
private final static String RETRY_MSG2 = |
|
97 |
"cannot retry due to server authentication, in streaming mode"; |
|
98 |
private final static String RETRY_MSG3 = |
|
99 |
"cannot retry due to redirection, in streaming mode"; |
|
100 |
||
101 |
/* |
|
102 |
* System properties related to error stream handling: |
|
103 |
* |
|
104 |
* sun.net.http.errorstream.enableBuffering = <boolean> |
|
105 |
* |
|
106 |
* With the above system property set to true (default is false), |
|
107 |
* when the response code is >=400, the HTTP handler will try to |
|
108 |
* buffer the response body (up to a certain amount and within a |
|
109 |
* time limit). Thus freeing up the underlying socket connection |
|
110 |
* for reuse. The rationale behind this is that usually when the |
|
111 |
* server responds with a >=400 error (client error or server |
|
112 |
* error, such as 404 file not found), the server will send a |
|
113 |
* small response body to explain who to contact and what to do to |
|
114 |
* recover. With this property set to true, even if the |
|
115 |
* application doesn't call getErrorStream(), read the response |
|
116 |
* body, and then call close(), the underlying socket connection |
|
117 |
* can still be kept-alive and reused. The following two system |
|
118 |
* properties provide further control to the error stream |
|
119 |
* buffering behaviour. |
|
120 |
* |
|
121 |
* sun.net.http.errorstream.timeout = <int> |
|
122 |
* the timeout (in millisec) waiting the error stream |
|
123 |
* to be buffered; default is 300 ms |
|
124 |
* |
|
125 |
* sun.net.http.errorstream.bufferSize = <int> |
|
126 |
* the size (in bytes) to use for the buffering the error stream; |
|
127 |
* default is 4k |
|
128 |
*/ |
|
129 |
||
130 |
||
131 |
/* Should we enable buffering of error streams? */ |
|
132 |
private static boolean enableESBuffer = false; |
|
133 |
||
134 |
/* timeout waiting for read for buffered error stream; |
|
135 |
*/ |
|
136 |
private static int timeout4ESBuffer = 0; |
|
137 |
||
138 |
/* buffer size for buffered error stream; |
|
139 |
*/ |
|
140 |
private static int bufSize4ES = 0; |
|
141 |
||
142 |
static { |
|
143 |
maxRedirects = java.security.AccessController.doPrivileged( |
|
51 | 144 |
new sun.security.action.GetIntegerAction( |
145 |
"http.maxRedirects", defaultmaxRedirects)).intValue(); |
|
2 | 146 |
version = java.security.AccessController.doPrivileged( |
147 |
new sun.security.action.GetPropertyAction("java.version")); |
|
148 |
String agent = java.security.AccessController.doPrivileged( |
|
149 |
new sun.security.action.GetPropertyAction("http.agent")); |
|
150 |
if (agent == null) { |
|
151 |
agent = "Java/"+version; |
|
152 |
} else { |
|
153 |
agent = agent + " Java/"+version; |
|
154 |
} |
|
155 |
userAgent = agent; |
|
156 |
validateProxy = java.security.AccessController.doPrivileged( |
|
157 |
new sun.security.action.GetBooleanAction( |
|
158 |
"http.auth.digest.validateProxy")).booleanValue(); |
|
159 |
validateServer = java.security.AccessController.doPrivileged( |
|
160 |
new sun.security.action.GetBooleanAction( |
|
161 |
"http.auth.digest.validateServer")).booleanValue(); |
|
162 |
||
163 |
enableESBuffer = java.security.AccessController.doPrivileged( |
|
164 |
new sun.security.action.GetBooleanAction( |
|
165 |
"sun.net.http.errorstream.enableBuffering")).booleanValue(); |
|
166 |
timeout4ESBuffer = java.security.AccessController.doPrivileged( |
|
167 |
new sun.security.action.GetIntegerAction( |
|
168 |
"sun.net.http.errorstream.timeout", 300)).intValue(); |
|
169 |
if (timeout4ESBuffer <= 0) { |
|
170 |
timeout4ESBuffer = 300; // use the default |
|
171 |
} |
|
172 |
||
173 |
bufSize4ES = java.security.AccessController.doPrivileged( |
|
174 |
new sun.security.action.GetIntegerAction( |
|
175 |
"sun.net.http.errorstream.bufferSize", 4096)).intValue(); |
|
176 |
if (bufSize4ES <= 0) { |
|
177 |
bufSize4ES = 4096; // use the default |
|
178 |
} |
|
179 |
||
180 |
||
181 |
} |
|
182 |
||
183 |
static final String httpVersion = "HTTP/1.1"; |
|
184 |
static final String acceptString = |
|
185 |
"text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"; |
|
186 |
||
187 |
// the following http request headers should NOT have their values |
|
188 |
// returned for security reasons. |
|
189 |
private static final String[] EXCLUDE_HEADERS = { |
|
190 |
"Proxy-Authorization", |
|
191 |
"Authorization" |
|
192 |
}; |
|
193 |
protected HttpClient http; |
|
194 |
protected Handler handler; |
|
195 |
protected Proxy instProxy; |
|
196 |
||
197 |
private CookieHandler cookieHandler; |
|
198 |
private ResponseCache cacheHandler; |
|
199 |
||
200 |
// the cached response, and cached response headers and body |
|
201 |
protected CacheResponse cachedResponse; |
|
202 |
private MessageHeader cachedHeaders; |
|
203 |
private InputStream cachedInputStream; |
|
204 |
||
205 |
/* output stream to server */ |
|
206 |
protected PrintStream ps = null; |
|
207 |
||
208 |
||
209 |
/* buffered error stream */ |
|
210 |
private InputStream errorStream = null; |
|
211 |
||
212 |
/* User set Cookies */ |
|
213 |
private boolean setUserCookies = true; |
|
214 |
private String userCookies = null; |
|
215 |
||
216 |
/* We only have a single static authenticator for now. |
|
217 |
* REMIND: backwards compatibility with JDK 1.1. Should be |
|
218 |
* eliminated for JDK 2.0. |
|
219 |
*/ |
|
220 |
private static HttpAuthenticator defaultAuth; |
|
221 |
||
222 |
/* all the headers we send |
|
223 |
* NOTE: do *NOT* dump out the content of 'requests' in the |
|
224 |
* output or stacktrace since it may contain security-sensitive |
|
225 |
* headers such as those defined in EXCLUDE_HEADERS. |
|
226 |
*/ |
|
227 |
private MessageHeader requests; |
|
228 |
||
229 |
/* The following two fields are only used with Digest Authentication */ |
|
230 |
String domain; /* The list of authentication domains */ |
|
231 |
DigestAuthentication.Parameters digestparams; |
|
232 |
||
233 |
/* Current credentials in use */ |
|
234 |
AuthenticationInfo currentProxyCredentials = null; |
|
235 |
AuthenticationInfo currentServerCredentials = null; |
|
236 |
boolean needToCheck = true; |
|
237 |
private boolean doingNTLM2ndStage = false; /* doing the 2nd stage of an NTLM server authentication */ |
|
238 |
private boolean doingNTLMp2ndStage = false; /* doing the 2nd stage of an NTLM proxy authentication */ |
|
239 |
/* try auth without calling Authenticator */ |
|
240 |
private boolean tryTransparentNTLMServer = NTLMAuthentication.supportsTransparentAuth(); |
|
241 |
private boolean tryTransparentNTLMProxy = NTLMAuthentication.supportsTransparentAuth(); |
|
242 |
Object authObj; |
|
243 |
||
244 |
/* Set if the user is manually setting the Authorization or Proxy-Authorization headers */ |
|
245 |
boolean isUserServerAuth; |
|
246 |
boolean isUserProxyAuth; |
|
247 |
||
248 |
/* Progress source */ |
|
249 |
protected ProgressSource pi; |
|
250 |
||
251 |
/* all the response headers we get back */ |
|
252 |
private MessageHeader responses; |
|
253 |
/* the stream _from_ the server */ |
|
254 |
private InputStream inputStream = null; |
|
255 |
/* post stream _to_ the server, if any */ |
|
256 |
private PosterOutputStream poster = null; |
|
257 |
||
258 |
/* Indicates if the std. request headers have been set in requests. */ |
|
259 |
private boolean setRequests=false; |
|
260 |
||
261 |
/* Indicates whether a request has already failed or not */ |
|
262 |
private boolean failedOnce=false; |
|
263 |
||
264 |
/* Remembered Exception, we will throw it again if somebody |
|
265 |
calls getInputStream after disconnect */ |
|
266 |
private Exception rememberedException = null; |
|
267 |
||
268 |
/* If we decide we want to reuse a client, we put it here */ |
|
269 |
private HttpClient reuseClient = null; |
|
270 |
||
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
271 |
/* Tunnel states */ |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
272 |
enum TunnelState { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
273 |
/* No tunnel */ |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
274 |
NONE, |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
275 |
|
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
276 |
/* Setting up a tunnel */ |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
277 |
SETUP, |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
278 |
|
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
279 |
/* Tunnel has been successfully setup */ |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
280 |
TUNNELING |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
281 |
} |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
282 |
|
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
283 |
private TunnelState tunnelState = TunnelState.NONE; |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
284 |
|
2 | 285 |
/* Redefine timeouts from java.net.URLConnection as we nee -1 to mean |
286 |
* not set. This is to ensure backward compatibility. |
|
287 |
*/ |
|
288 |
private int connectTimeout = -1; |
|
289 |
private int readTimeout = -1; |
|
290 |
||
291 |
/* |
|
292 |
* privileged request password authentication |
|
293 |
* |
|
294 |
*/ |
|
295 |
private static PasswordAuthentication |
|
296 |
privilegedRequestPasswordAuthentication( |
|
297 |
final String host, |
|
298 |
final InetAddress addr, |
|
299 |
final int port, |
|
300 |
final String protocol, |
|
301 |
final String prompt, |
|
302 |
final String scheme, |
|
303 |
final URL url, |
|
304 |
final RequestorType authType) { |
|
51 | 305 |
return java.security.AccessController.doPrivileged( |
306 |
new java.security.PrivilegedAction<PasswordAuthentication>() { |
|
307 |
public PasswordAuthentication run() { |
|
2 | 308 |
return Authenticator.requestPasswordAuthentication( |
309 |
host, addr, port, protocol, |
|
310 |
prompt, scheme, url, authType); |
|
311 |
} |
|
312 |
}); |
|
313 |
} |
|
314 |
||
315 |
/* |
|
316 |
* checks the validity of http message header and throws |
|
317 |
* IllegalArgumentException if invalid. |
|
318 |
*/ |
|
319 |
private void checkMessageHeader(String key, String value) { |
|
320 |
char LF = '\n'; |
|
321 |
int index = key.indexOf(LF); |
|
322 |
if (index != -1) { |
|
323 |
throw new IllegalArgumentException( |
|
324 |
"Illegal character(s) in message header field: " + key); |
|
325 |
} |
|
326 |
else { |
|
327 |
if (value == null) { |
|
328 |
return; |
|
329 |
} |
|
330 |
||
331 |
index = value.indexOf(LF); |
|
332 |
while (index != -1) { |
|
333 |
index++; |
|
334 |
if (index < value.length()) { |
|
335 |
char c = value.charAt(index); |
|
336 |
if ((c==' ') || (c=='\t')) { |
|
337 |
// ok, check the next occurrence |
|
338 |
index = value.indexOf(LF, index); |
|
339 |
continue; |
|
340 |
} |
|
341 |
} |
|
342 |
throw new IllegalArgumentException( |
|
343 |
"Illegal character(s) in message header value: " + value); |
|
344 |
} |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
/* adds the standard key/val pairs to reqests if necessary & write to |
|
349 |
* given PrintStream |
|
350 |
*/ |
|
351 |
private void writeRequests() throws IOException { |
|
352 |
/* print all message headers in the MessageHeader |
|
353 |
* onto the wire - all the ones we've set and any |
|
354 |
* others that have been set |
|
355 |
*/ |
|
356 |
// send any pre-emptive authentication |
|
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
357 |
if (http.usingProxy && tunnelState() != TunnelState.TUNNELING) { |
2 | 358 |
setPreemptiveProxyAuthentication(requests); |
359 |
} |
|
360 |
if (!setRequests) { |
|
361 |
||
362 |
/* We're very particular about the order in which we |
|
363 |
* set the request headers here. The order should not |
|
364 |
* matter, but some careless CGI programs have been |
|
365 |
* written to expect a very particular order of the |
|
366 |
* standard headers. To name names, the order in which |
|
367 |
* Navigator3.0 sends them. In particular, we make *sure* |
|
368 |
* to send Content-type: <> and Content-length:<> second |
|
369 |
* to last and last, respectively, in the case of a POST |
|
370 |
* request. |
|
371 |
*/ |
|
372 |
if (!failedOnce) |
|
373 |
requests.prepend(method + " " + http.getURLFile()+" " + |
|
374 |
httpVersion, null); |
|
375 |
if (!getUseCaches()) { |
|
376 |
requests.setIfNotSet ("Cache-Control", "no-cache"); |
|
377 |
requests.setIfNotSet ("Pragma", "no-cache"); |
|
378 |
} |
|
379 |
requests.setIfNotSet("User-Agent", userAgent); |
|
380 |
int port = url.getPort(); |
|
381 |
String host = url.getHost(); |
|
382 |
if (port != -1 && port != url.getDefaultPort()) { |
|
383 |
host += ":" + String.valueOf(port); |
|
384 |
} |
|
385 |
requests.setIfNotSet("Host", host); |
|
386 |
requests.setIfNotSet("Accept", acceptString); |
|
387 |
||
388 |
/* |
|
389 |
* For HTTP/1.1 the default behavior is to keep connections alive. |
|
390 |
* However, we may be talking to a 1.0 server so we should set |
|
391 |
* keep-alive just in case, except if we have encountered an error |
|
392 |
* or if keep alive is disabled via a system property |
|
393 |
*/ |
|
394 |
||
395 |
// Try keep-alive only on first attempt |
|
396 |
if (!failedOnce && http.getHttpKeepAliveSet()) { |
|
397 |
if (http.usingProxy) { |
|
398 |
requests.setIfNotSet("Proxy-Connection", "keep-alive"); |
|
399 |
} else { |
|
400 |
requests.setIfNotSet("Connection", "keep-alive"); |
|
401 |
} |
|
402 |
} else { |
|
403 |
/* |
|
404 |
* RFC 2616 HTTP/1.1 section 14.10 says: |
|
405 |
* HTTP/1.1 applications that do not support persistent |
|
406 |
* connections MUST include the "close" connection option |
|
407 |
* in every message |
|
408 |
*/ |
|
409 |
requests.setIfNotSet("Connection", "close"); |
|
410 |
} |
|
411 |
// Set modified since if necessary |
|
412 |
long modTime = getIfModifiedSince(); |
|
413 |
if (modTime != 0 ) { |
|
414 |
Date date = new Date(modTime); |
|
415 |
//use the preferred date format according to RFC 2068(HTTP1.1), |
|
416 |
// RFC 822 and RFC 1123 |
|
417 |
SimpleDateFormat fo = |
|
418 |
new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); |
|
419 |
fo.setTimeZone(TimeZone.getTimeZone("GMT")); |
|
420 |
requests.setIfNotSet("If-Modified-Since", fo.format(date)); |
|
421 |
} |
|
422 |
// check for preemptive authorization |
|
423 |
AuthenticationInfo sauth = AuthenticationInfo.getServerAuth(url); |
|
424 |
if (sauth != null && sauth.supportsPreemptiveAuthorization() ) { |
|
425 |
// Sets "Authorization" |
|
426 |
requests.setIfNotSet(sauth.getHeaderName(), sauth.getHeaderValue(url,method)); |
|
427 |
currentServerCredentials = sauth; |
|
428 |
} |
|
429 |
||
430 |
if (!method.equals("PUT") && (poster != null || streaming())) { |
|
431 |
requests.setIfNotSet ("Content-type", |
|
432 |
"application/x-www-form-urlencoded"); |
|
433 |
} |
|
434 |
||
435 |
if (streaming()) { |
|
436 |
if (chunkLength != -1) { |
|
437 |
requests.set ("Transfer-Encoding", "chunked"); |
|
438 |
} else { |
|
439 |
requests.set ("Content-Length", String.valueOf(fixedContentLength)); |
|
440 |
} |
|
441 |
} else if (poster != null) { |
|
442 |
/* add Content-Length & POST/PUT data */ |
|
443 |
synchronized (poster) { |
|
444 |
/* close it, so no more data can be added */ |
|
445 |
poster.close(); |
|
446 |
requests.set("Content-Length", |
|
447 |
String.valueOf(poster.size())); |
|
448 |
} |
|
449 |
} |
|
450 |
||
451 |
// get applicable cookies based on the uri and request headers |
|
452 |
// add them to the existing request headers |
|
453 |
setCookieHeader(); |
|
454 |
||
455 |
setRequests=true; |
|
456 |
} |
|
457 |
if(logger.isLoggable(Level.FINEST)) { |
|
458 |
logger.fine(requests.toString()); |
|
459 |
} |
|
460 |
http.writeRequests(requests, poster); |
|
461 |
if (ps.checkError()) { |
|
462 |
String proxyHost = http.getProxyHostUsed(); |
|
463 |
int proxyPort = http.getProxyPortUsed(); |
|
464 |
disconnectInternal(); |
|
465 |
if (failedOnce) { |
|
466 |
throw new IOException("Error writing to server"); |
|
467 |
} else { // try once more |
|
468 |
failedOnce=true; |
|
469 |
if (proxyHost != null) { |
|
470 |
setProxiedClient(url, proxyHost, proxyPort); |
|
471 |
} else { |
|
472 |
setNewClient (url); |
|
473 |
} |
|
474 |
ps = (PrintStream) http.getOutputStream(); |
|
475 |
connected=true; |
|
476 |
responses = new MessageHeader(); |
|
477 |
setRequests=false; |
|
478 |
writeRequests(); |
|
479 |
} |
|
480 |
} |
|
481 |
} |
|
482 |
||
483 |
||
484 |
/** |
|
485 |
* Create a new HttpClient object, bypassing the cache of |
|
486 |
* HTTP client objects/connections. |
|
487 |
* |
|
488 |
* @param url the URL being accessed |
|
489 |
*/ |
|
490 |
protected void setNewClient (URL url) |
|
491 |
throws IOException { |
|
492 |
setNewClient(url, false); |
|
493 |
} |
|
494 |
||
495 |
/** |
|
496 |
* Obtain a HttpsClient object. Use the cached copy if specified. |
|
497 |
* |
|
498 |
* @param url the URL being accessed |
|
499 |
* @param useCache whether the cached connection should be used |
|
500 |
* if present |
|
501 |
*/ |
|
502 |
protected void setNewClient (URL url, boolean useCache) |
|
503 |
throws IOException { |
|
504 |
http = HttpClient.New(url, null, -1, useCache, connectTimeout); |
|
505 |
http.setReadTimeout(readTimeout); |
|
506 |
} |
|
507 |
||
508 |
||
509 |
/** |
|
510 |
* Create a new HttpClient object, set up so that it uses |
|
511 |
* per-instance proxying to the given HTTP proxy. This |
|
512 |
* bypasses the cache of HTTP client objects/connections. |
|
513 |
* |
|
514 |
* @param url the URL being accessed |
|
515 |
* @param proxyHost the proxy host to use |
|
516 |
* @param proxyPort the proxy port to use |
|
517 |
*/ |
|
518 |
protected void setProxiedClient (URL url, String proxyHost, int proxyPort) |
|
519 |
throws IOException { |
|
520 |
setProxiedClient(url, proxyHost, proxyPort, false); |
|
521 |
} |
|
522 |
||
523 |
/** |
|
524 |
* Obtain a HttpClient object, set up so that it uses per-instance |
|
525 |
* proxying to the given HTTP proxy. Use the cached copy of HTTP |
|
526 |
* client objects/connections if specified. |
|
527 |
* |
|
528 |
* @param url the URL being accessed |
|
529 |
* @param proxyHost the proxy host to use |
|
530 |
* @param proxyPort the proxy port to use |
|
531 |
* @param useCache whether the cached connection should be used |
|
532 |
* if present |
|
533 |
*/ |
|
534 |
protected void setProxiedClient (URL url, |
|
535 |
String proxyHost, int proxyPort, |
|
536 |
boolean useCache) |
|
537 |
throws IOException { |
|
538 |
proxiedConnect(url, proxyHost, proxyPort, useCache); |
|
539 |
} |
|
540 |
||
541 |
protected void proxiedConnect(URL url, |
|
542 |
String proxyHost, int proxyPort, |
|
543 |
boolean useCache) |
|
544 |
throws IOException { |
|
545 |
http = HttpClient.New (url, proxyHost, proxyPort, useCache, connectTimeout); |
|
546 |
http.setReadTimeout(readTimeout); |
|
547 |
} |
|
548 |
||
549 |
protected HttpURLConnection(URL u, Handler handler) |
|
550 |
throws IOException { |
|
551 |
// we set proxy == null to distinguish this case with the case |
|
552 |
// when per connection proxy is set |
|
553 |
this(u, null, handler); |
|
554 |
} |
|
555 |
||
556 |
public HttpURLConnection(URL u, String host, int port) { |
|
557 |
this(u, new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(host, port))); |
|
558 |
} |
|
559 |
||
560 |
/** this constructor is used by other protocol handlers such as ftp |
|
561 |
that want to use http to fetch urls on their behalf.*/ |
|
562 |
public HttpURLConnection(URL u, Proxy p) { |
|
563 |
this(u, p, new Handler()); |
|
564 |
} |
|
565 |
||
566 |
protected HttpURLConnection(URL u, Proxy p, Handler handler) { |
|
567 |
super(u); |
|
568 |
requests = new MessageHeader(); |
|
569 |
responses = new MessageHeader(); |
|
570 |
this.handler = handler; |
|
571 |
instProxy = p; |
|
51 | 572 |
cookieHandler = java.security.AccessController.doPrivileged( |
573 |
new java.security.PrivilegedAction<CookieHandler>() { |
|
574 |
public CookieHandler run() { |
|
2 | 575 |
return CookieHandler.getDefault(); |
576 |
} |
|
577 |
}); |
|
51 | 578 |
cacheHandler = java.security.AccessController.doPrivileged( |
579 |
new java.security.PrivilegedAction<ResponseCache>() { |
|
580 |
public ResponseCache run() { |
|
2 | 581 |
return ResponseCache.getDefault(); |
582 |
} |
|
583 |
}); |
|
584 |
} |
|
585 |
||
586 |
/** |
|
587 |
* @deprecated. Use java.net.Authenticator.setDefault() instead. |
|
588 |
*/ |
|
589 |
public static void setDefaultAuthenticator(HttpAuthenticator a) { |
|
590 |
defaultAuth = a; |
|
591 |
} |
|
592 |
||
593 |
/** |
|
594 |
* opens a stream allowing redirects only to the same host. |
|
595 |
*/ |
|
596 |
public static InputStream openConnectionCheckRedirects(URLConnection c) |
|
597 |
throws IOException |
|
598 |
{ |
|
599 |
boolean redir; |
|
600 |
int redirects = 0; |
|
601 |
InputStream in = null; |
|
602 |
||
603 |
do { |
|
604 |
if (c instanceof HttpURLConnection) { |
|
605 |
((HttpURLConnection) c).setInstanceFollowRedirects(false); |
|
606 |
} |
|
607 |
||
608 |
// We want to open the input stream before |
|
609 |
// getting headers, because getHeaderField() |
|
610 |
// et al swallow IOExceptions. |
|
611 |
in = c.getInputStream(); |
|
612 |
redir = false; |
|
613 |
||
614 |
if (c instanceof HttpURLConnection) { |
|
615 |
HttpURLConnection http = (HttpURLConnection) c; |
|
616 |
int stat = http.getResponseCode(); |
|
617 |
if (stat >= 300 && stat <= 307 && stat != 306 && |
|
618 |
stat != HttpURLConnection.HTTP_NOT_MODIFIED) { |
|
619 |
URL base = http.getURL(); |
|
620 |
String loc = http.getHeaderField("Location"); |
|
621 |
URL target = null; |
|
622 |
if (loc != null) { |
|
623 |
target = new URL(base, loc); |
|
624 |
} |
|
625 |
http.disconnect(); |
|
626 |
if (target == null |
|
627 |
|| !base.getProtocol().equals(target.getProtocol()) |
|
628 |
|| base.getPort() != target.getPort() |
|
629 |
|| !hostsEqual(base, target) |
|
630 |
|| redirects >= 5) |
|
631 |
{ |
|
632 |
throw new SecurityException("illegal URL redirect"); |
|
633 |
} |
|
634 |
redir = true; |
|
635 |
c = target.openConnection(); |
|
636 |
redirects++; |
|
637 |
} |
|
638 |
} |
|
639 |
} while (redir); |
|
640 |
return in; |
|
641 |
} |
|
642 |
||
643 |
||
644 |
// |
|
645 |
// Same as java.net.URL.hostsEqual |
|
646 |
// |
|
647 |
private static boolean hostsEqual(URL u1, URL u2) { |
|
648 |
final String h1 = u1.getHost(); |
|
649 |
final String h2 = u2.getHost(); |
|
650 |
||
651 |
if (h1 == null) { |
|
652 |
return h2 == null; |
|
653 |
} else if (h2 == null) { |
|
654 |
return false; |
|
655 |
} else if (h1.equalsIgnoreCase(h2)) { |
|
656 |
return true; |
|
657 |
} |
|
658 |
// Have to resolve addresses before comparing, otherwise |
|
659 |
// names like tachyon and tachyon.eng would compare different |
|
660 |
final boolean result[] = {false}; |
|
661 |
||
662 |
java.security.AccessController.doPrivileged( |
|
51 | 663 |
new java.security.PrivilegedAction<Void>() { |
664 |
public Void run() { |
|
2 | 665 |
try { |
666 |
InetAddress a1 = InetAddress.getByName(h1); |
|
667 |
InetAddress a2 = InetAddress.getByName(h2); |
|
668 |
result[0] = a1.equals(a2); |
|
669 |
} catch(UnknownHostException e) { |
|
670 |
} catch(SecurityException e) { |
|
671 |
} |
|
672 |
return null; |
|
673 |
} |
|
674 |
}); |
|
675 |
||
676 |
return result[0]; |
|
677 |
} |
|
678 |
||
679 |
// overridden in HTTPS subclass |
|
680 |
||
681 |
public void connect() throws IOException { |
|
682 |
plainConnect(); |
|
683 |
} |
|
684 |
||
685 |
private boolean checkReuseConnection () { |
|
686 |
if (connected) { |
|
687 |
return true; |
|
688 |
} |
|
689 |
if (reuseClient != null) { |
|
690 |
http = reuseClient; |
|
691 |
http.setReadTimeout(getReadTimeout()); |
|
692 |
http.reuse = false; |
|
693 |
reuseClient = null; |
|
694 |
connected = true; |
|
695 |
return true; |
|
696 |
} |
|
697 |
return false; |
|
698 |
} |
|
699 |
||
700 |
protected void plainConnect() throws IOException { |
|
701 |
if (connected) { |
|
702 |
return; |
|
703 |
} |
|
704 |
// try to see if request can be served from local cache |
|
705 |
if (cacheHandler != null && getUseCaches()) { |
|
706 |
try { |
|
707 |
URI uri = ParseUtil.toURI(url); |
|
708 |
if (uri != null) { |
|
709 |
cachedResponse = cacheHandler.get(uri, getRequestMethod(), requests.getHeaders(EXCLUDE_HEADERS)); |
|
710 |
if ("https".equalsIgnoreCase(uri.getScheme()) |
|
711 |
&& !(cachedResponse instanceof SecureCacheResponse)) { |
|
712 |
cachedResponse = null; |
|
713 |
} |
|
714 |
if (cachedResponse != null) { |
|
715 |
cachedHeaders = mapToMessageHeader(cachedResponse.getHeaders()); |
|
716 |
cachedInputStream = cachedResponse.getBody(); |
|
717 |
} |
|
718 |
} |
|
719 |
} catch (IOException ioex) { |
|
720 |
// ignore and commence normal connection |
|
721 |
} |
|
722 |
if (cachedHeaders != null && cachedInputStream != null) { |
|
723 |
connected = true; |
|
724 |
return; |
|
725 |
} else { |
|
726 |
cachedResponse = null; |
|
727 |
} |
|
728 |
} |
|
729 |
try { |
|
730 |
/* Try to open connections using the following scheme, |
|
731 |
* return on the first one that's successful: |
|
732 |
* 1) if (instProxy != null) |
|
733 |
* connect to instProxy; raise exception if failed |
|
734 |
* 2) else use system default ProxySelector |
|
735 |
* 3) is 2) fails, make direct connection |
|
736 |
*/ |
|
737 |
||
738 |
if (instProxy == null) { // no instance Proxy is set |
|
739 |
/** |
|
740 |
* Do we have to use a proxy? |
|
741 |
*/ |
|
51 | 742 |
ProxySelector sel = |
2 | 743 |
java.security.AccessController.doPrivileged( |
51 | 744 |
new java.security.PrivilegedAction<ProxySelector>() { |
745 |
public ProxySelector run() { |
|
2 | 746 |
return ProxySelector.getDefault(); |
747 |
} |
|
748 |
}); |
|
749 |
Proxy p = null; |
|
750 |
if (sel != null) { |
|
751 |
URI uri = sun.net.www.ParseUtil.toURI(url); |
|
752 |
Iterator<Proxy> it = sel.select(uri).iterator(); |
|
753 |
while (it.hasNext()) { |
|
754 |
p = it.next(); |
|
755 |
try { |
|
756 |
if (!failedOnce) { |
|
757 |
http = getNewHttpClient(url, p, connectTimeout); |
|
758 |
http.setReadTimeout(readTimeout); |
|
759 |
} else { |
|
760 |
// make sure to construct new connection if first |
|
761 |
// attempt failed |
|
762 |
http = getNewHttpClient(url, p, connectTimeout, false); |
|
763 |
http.setReadTimeout(readTimeout); |
|
764 |
} |
|
765 |
break; |
|
766 |
} catch (IOException ioex) { |
|
767 |
if (p != Proxy.NO_PROXY) { |
|
768 |
sel.connectFailed(uri, p.address(), ioex); |
|
769 |
if (!it.hasNext()) { |
|
770 |
// fallback to direct connection |
|
771 |
http = getNewHttpClient(url, null, connectTimeout, false); |
|
772 |
http.setReadTimeout(readTimeout); |
|
773 |
break; |
|
774 |
} |
|
775 |
} else { |
|
776 |
throw ioex; |
|
777 |
} |
|
778 |
continue; |
|
779 |
} |
|
780 |
} |
|
781 |
} else { |
|
782 |
// No proxy selector, create http client with no proxy |
|
783 |
if (!failedOnce) { |
|
784 |
http = getNewHttpClient(url, null, connectTimeout); |
|
785 |
http.setReadTimeout(readTimeout); |
|
786 |
} else { |
|
787 |
// make sure to construct new connection if first |
|
788 |
// attempt failed |
|
789 |
http = getNewHttpClient(url, null, connectTimeout, false); |
|
790 |
http.setReadTimeout(readTimeout); |
|
791 |
} |
|
792 |
} |
|
793 |
} else { |
|
794 |
if (!failedOnce) { |
|
795 |
http = getNewHttpClient(url, instProxy, connectTimeout); |
|
796 |
http.setReadTimeout(readTimeout); |
|
797 |
} else { |
|
798 |
// make sure to construct new connection if first |
|
799 |
// attempt failed |
|
800 |
http = getNewHttpClient(url, instProxy, connectTimeout, false); |
|
801 |
http.setReadTimeout(readTimeout); |
|
802 |
} |
|
803 |
} |
|
804 |
||
805 |
ps = (PrintStream)http.getOutputStream(); |
|
806 |
} catch (IOException e) { |
|
807 |
throw e; |
|
808 |
} |
|
809 |
// constructor to HTTP client calls openserver |
|
810 |
connected = true; |
|
811 |
} |
|
812 |
||
813 |
// subclass HttpsClient will overwrite & return an instance of HttpsClient |
|
814 |
protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout) |
|
815 |
throws IOException { |
|
816 |
return HttpClient.New(url, p, connectTimeout); |
|
817 |
} |
|
818 |
||
819 |
// subclass HttpsClient will overwrite & return an instance of HttpsClient |
|
820 |
protected HttpClient getNewHttpClient(URL url, Proxy p, |
|
821 |
int connectTimeout, boolean useCache) |
|
822 |
throws IOException { |
|
823 |
return HttpClient.New(url, p, connectTimeout, useCache); |
|
824 |
} |
|
825 |
||
826 |
/* |
|
827 |
* Allowable input/output sequences: |
|
828 |
* [interpreted as POST/PUT] |
|
829 |
* - get output, [write output,] get input, [read input] |
|
830 |
* - get output, [write output] |
|
831 |
* [interpreted as GET] |
|
832 |
* - get input, [read input] |
|
833 |
* Disallowed: |
|
834 |
* - get input, [read input,] get output, [write output] |
|
835 |
*/ |
|
836 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
837 |
@Override |
2 | 838 |
public synchronized OutputStream getOutputStream() throws IOException { |
839 |
||
840 |
try { |
|
841 |
if (!doOutput) { |
|
842 |
throw new ProtocolException("cannot write to a URLConnection" |
|
843 |
+ " if doOutput=false - call setDoOutput(true)"); |
|
844 |
} |
|
845 |
||
846 |
if (method.equals("GET")) { |
|
847 |
method = "POST"; // Backward compatibility |
|
848 |
} |
|
849 |
if (!"POST".equals(method) && !"PUT".equals(method) && |
|
850 |
"http".equals(url.getProtocol())) { |
|
851 |
throw new ProtocolException("HTTP method " + method + |
|
852 |
" doesn't support output"); |
|
853 |
} |
|
854 |
||
855 |
// if there's already an input stream open, throw an exception |
|
856 |
if (inputStream != null) { |
|
857 |
throw new ProtocolException("Cannot write output after reading input."); |
|
858 |
} |
|
859 |
||
860 |
if (!checkReuseConnection()) |
|
861 |
connect(); |
|
862 |
||
863 |
/* REMIND: This exists to fix the HttpsURLConnection subclass. |
|
864 |
* Hotjava needs to run on JDK1.1FCS. Do proper fix in subclass |
|
865 |
* for 1.2 and remove this. |
|
866 |
*/ |
|
867 |
||
868 |
if (streaming() && strOutputStream == null) { |
|
869 |
writeRequests(); |
|
870 |
} |
|
871 |
ps = (PrintStream)http.getOutputStream(); |
|
872 |
if (streaming()) { |
|
873 |
if (strOutputStream == null) { |
|
874 |
if (fixedContentLength != -1) { |
|
875 |
strOutputStream = new StreamingOutputStream (ps, fixedContentLength); |
|
876 |
} else if (chunkLength != -1) { |
|
877 |
strOutputStream = |
|
878 |
new StreamingOutputStream (new ChunkedOutputStream (ps, chunkLength), -1); |
|
879 |
} |
|
880 |
} |
|
881 |
return strOutputStream; |
|
882 |
} else { |
|
883 |
if (poster == null) { |
|
884 |
poster = new PosterOutputStream(); |
|
885 |
} |
|
886 |
return poster; |
|
887 |
} |
|
888 |
} catch (RuntimeException e) { |
|
889 |
disconnectInternal(); |
|
890 |
throw e; |
|
891 |
} catch (IOException e) { |
|
892 |
disconnectInternal(); |
|
893 |
throw e; |
|
894 |
} |
|
895 |
} |
|
896 |
||
897 |
private boolean streaming () { |
|
898 |
return (fixedContentLength != -1) || (chunkLength != -1); |
|
899 |
} |
|
900 |
||
901 |
/* |
|
902 |
* get applicable cookies based on the uri and request headers |
|
903 |
* add them to the existing request headers |
|
904 |
*/ |
|
905 |
private void setCookieHeader() throws IOException { |
|
906 |
if (cookieHandler != null) { |
|
907 |
// we only want to capture the user defined Cookies once, as |
|
908 |
// they cannot be changed by user code after we are connected, |
|
909 |
// only internally. |
|
910 |
if (setUserCookies) { |
|
911 |
int k = requests.getKey("Cookie"); |
|
912 |
if ( k != -1) |
|
913 |
userCookies = requests.getValue(k); |
|
914 |
setUserCookies = false; |
|
915 |
} |
|
916 |
||
917 |
// remove old Cookie header before setting new one. |
|
918 |
requests.remove("Cookie"); |
|
919 |
||
920 |
URI uri = ParseUtil.toURI(url); |
|
921 |
if (uri != null) { |
|
51 | 922 |
Map<String, List<String>> cookies |
923 |
= cookieHandler.get( |
|
924 |
uri, requests.getHeaders(EXCLUDE_HEADERS)); |
|
2 | 925 |
if (!cookies.isEmpty()) { |
51 | 926 |
for (Map.Entry<String, List<String>> entry : |
927 |
cookies.entrySet()) { |
|
928 |
String key = entry.getKey(); |
|
2 | 929 |
// ignore all entries that don't have "Cookie" |
930 |
// or "Cookie2" as keys |
|
931 |
if (!"Cookie".equalsIgnoreCase(key) && |
|
932 |
!"Cookie2".equalsIgnoreCase(key)) { |
|
933 |
continue; |
|
934 |
} |
|
51 | 935 |
List<String> l = entry.getValue(); |
2 | 936 |
if (l != null && !l.isEmpty()) { |
937 |
StringBuilder cookieValue = new StringBuilder(); |
|
51 | 938 |
for (String value : l) { |
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
939 |
cookieValue.append(value).append("; "); |
2 | 940 |
} |
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
941 |
// strip off the trailing '; ' |
2 | 942 |
try { |
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
943 |
requests.add(key, cookieValue.substring(0, cookieValue.length() - 2)); |
2 | 944 |
} catch (StringIndexOutOfBoundsException ignored) { |
945 |
// no-op |
|
946 |
} |
|
947 |
} |
|
948 |
} |
|
949 |
} |
|
950 |
} |
|
951 |
if (userCookies != null) { |
|
952 |
int k; |
|
953 |
if ((k = requests.getKey("Cookie")) != -1) |
|
954 |
requests.set("Cookie", requests.getValue(k) + ";" + userCookies); |
|
955 |
else |
|
956 |
requests.set("Cookie", userCookies); |
|
957 |
} |
|
958 |
||
959 |
} // end of getting cookies |
|
960 |
} |
|
961 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
962 |
@Override |
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
963 |
@SuppressWarnings("empty-statement") |
2 | 964 |
public synchronized InputStream getInputStream() throws IOException { |
965 |
||
966 |
if (!doInput) { |
|
967 |
throw new ProtocolException("Cannot read from URLConnection" |
|
968 |
+ " if doInput=false (call setDoInput(true))"); |
|
969 |
} |
|
970 |
||
971 |
if (rememberedException != null) { |
|
972 |
if (rememberedException instanceof RuntimeException) |
|
973 |
throw new RuntimeException(rememberedException); |
|
974 |
else { |
|
975 |
throw getChainedException((IOException)rememberedException); |
|
976 |
} |
|
977 |
} |
|
978 |
||
979 |
if (inputStream != null) { |
|
980 |
return inputStream; |
|
981 |
} |
|
982 |
||
983 |
if (streaming() ) { |
|
984 |
if (strOutputStream == null) { |
|
985 |
getOutputStream(); |
|
986 |
} |
|
987 |
/* make sure stream is closed */ |
|
988 |
strOutputStream.close (); |
|
989 |
if (!strOutputStream.writtenOK()) { |
|
990 |
throw new IOException ("Incomplete output stream"); |
|
991 |
} |
|
992 |
} |
|
993 |
||
994 |
int redirects = 0; |
|
995 |
int respCode = 0; |
|
996 |
long cl = -1; |
|
997 |
AuthenticationInfo serverAuthentication = null; |
|
998 |
AuthenticationInfo proxyAuthentication = null; |
|
999 |
AuthenticationHeader srvHdr = null; |
|
1000 |
||
1001 |
/** |
|
1002 |
* Failed Negotiate |
|
1003 |
* |
|
1004 |
* In some cases, the Negotiate auth is supported for the |
|
1005 |
* remote host but the negotiate process still fails (For |
|
1006 |
* example, if the web page is located on a backend server |
|
1007 |
* and delegation is needed but fails). The authentication |
|
1008 |
* process will start again, and we need to detect this |
|
1009 |
* kind of failure and do proper fallback (say, to NTLM). |
|
1010 |
* |
|
1011 |
* In order to achieve this, the inNegotiate flag is set |
|
1012 |
* when the first negotiate challenge is met (and reset |
|
1013 |
* if authentication is finished). If a fresh new negotiate |
|
1014 |
* challenge (no parameter) is found while inNegotiate is |
|
1015 |
* set, we know there's a failed auth attempt recently. |
|
1016 |
* Here we'll ignore the header line so that fallback |
|
1017 |
* can be practiced. |
|
1018 |
* |
|
1019 |
* inNegotiateProxy is for proxy authentication. |
|
1020 |
*/ |
|
1021 |
boolean inNegotiate = false; |
|
1022 |
boolean inNegotiateProxy = false; |
|
1023 |
||
1024 |
// If the user has set either of these headers then do not remove them |
|
1025 |
isUserServerAuth = requests.getKey("Authorization") != -1; |
|
1026 |
isUserProxyAuth = requests.getKey("Proxy-Authorization") != -1; |
|
1027 |
||
1028 |
try { |
|
1029 |
do { |
|
1030 |
if (!checkReuseConnection()) |
|
1031 |
connect(); |
|
1032 |
||
1033 |
if (cachedInputStream != null) { |
|
1034 |
return cachedInputStream; |
|
1035 |
} |
|
1036 |
||
1037 |
// Check if URL should be metered |
|
1038 |
boolean meteredInput = ProgressMonitor.getDefault().shouldMeterInput(url, method); |
|
1039 |
||
1040 |
if (meteredInput) { |
|
1041 |
pi = new ProgressSource(url, method); |
|
1042 |
pi.beginTracking(); |
|
1043 |
} |
|
1044 |
||
1045 |
/* REMIND: This exists to fix the HttpsURLConnection subclass. |
|
1046 |
* Hotjava needs to run on JDK1.1FCS. Do proper fix once a |
|
1047 |
* proper solution for SSL can be found. |
|
1048 |
*/ |
|
1049 |
ps = (PrintStream)http.getOutputStream(); |
|
1050 |
||
1051 |
if (!streaming()) { |
|
1052 |
writeRequests(); |
|
1053 |
} |
|
1054 |
http.parseHTTP(responses, pi, this); |
|
1055 |
if(logger.isLoggable(Level.FINEST)) { |
|
1056 |
logger.fine(responses.toString()); |
|
1057 |
} |
|
1058 |
inputStream = http.getInputStream(); |
|
1059 |
||
1060 |
respCode = getResponseCode(); |
|
1061 |
if (respCode == HTTP_PROXY_AUTH) { |
|
1062 |
if (streaming()) { |
|
1063 |
disconnectInternal(); |
|
1064 |
throw new HttpRetryException ( |
|
1065 |
RETRY_MSG1, HTTP_PROXY_AUTH); |
|
1066 |
} |
|
1067 |
||
1068 |
// Read comments labeled "Failed Negotiate" for details. |
|
1069 |
boolean dontUseNegotiate = false; |
|
1070 |
Iterator iter = responses.multiValueIterator("Proxy-Authenticate"); |
|
1071 |
while (iter.hasNext()) { |
|
1072 |
String value = ((String)iter.next()).trim(); |
|
1073 |
if (value.equalsIgnoreCase("Negotiate") || |
|
1074 |
value.equalsIgnoreCase("Kerberos")) { |
|
1075 |
if (!inNegotiateProxy) { |
|
1076 |
inNegotiateProxy = true; |
|
1077 |
} else { |
|
1078 |
dontUseNegotiate = true; |
|
1079 |
doingNTLMp2ndStage = false; |
|
1080 |
proxyAuthentication = null; |
|
1081 |
} |
|
1082 |
break; |
|
1083 |
} |
|
1084 |
} |
|
1085 |
||
1086 |
// changes: add a 3rd parameter to the constructor of |
|
1087 |
// AuthenticationHeader, so that NegotiateAuthentication. |
|
1088 |
// isSupported can be tested. |
|
1089 |
// The other 2 appearances of "new AuthenticationHeader" is |
|
1090 |
// altered in similar ways. |
|
1091 |
||
1092 |
AuthenticationHeader authhdr = new AuthenticationHeader ( |
|
1093 |
"Proxy-Authenticate", responses, |
|
1094 |
http.getProxyHostUsed(), dontUseNegotiate |
|
1095 |
); |
|
1096 |
||
1097 |
if (!doingNTLMp2ndStage) { |
|
1098 |
proxyAuthentication = |
|
1099 |
resetProxyAuthentication(proxyAuthentication, authhdr); |
|
1100 |
if (proxyAuthentication != null) { |
|
1101 |
redirects++; |
|
1102 |
disconnectInternal(); |
|
1103 |
continue; |
|
1104 |
} |
|
1105 |
} else { |
|
1106 |
/* in this case, only one header field will be present */ |
|
1107 |
String raw = responses.findValue ("Proxy-Authenticate"); |
|
1108 |
reset (); |
|
1109 |
if (!proxyAuthentication.setHeaders(this, |
|
1110 |
authhdr.headerParser(), raw)) { |
|
1111 |
disconnectInternal(); |
|
1112 |
throw new IOException ("Authentication failure"); |
|
1113 |
} |
|
1114 |
if (serverAuthentication != null && srvHdr != null && |
|
1115 |
!serverAuthentication.setHeaders(this, |
|
1116 |
srvHdr.headerParser(), raw)) { |
|
1117 |
disconnectInternal (); |
|
1118 |
throw new IOException ("Authentication failure"); |
|
1119 |
} |
|
1120 |
authObj = null; |
|
1121 |
doingNTLMp2ndStage = false; |
|
1122 |
continue; |
|
1123 |
} |
|
1124 |
} |
|
1125 |
||
1126 |
// cache proxy authentication info |
|
1127 |
if (proxyAuthentication != null) { |
|
1128 |
// cache auth info on success, domain header not relevant. |
|
1129 |
proxyAuthentication.addToCache(); |
|
1130 |
} |
|
1131 |
||
1132 |
if (respCode == HTTP_UNAUTHORIZED) { |
|
1133 |
if (streaming()) { |
|
1134 |
disconnectInternal(); |
|
1135 |
throw new HttpRetryException ( |
|
1136 |
RETRY_MSG2, HTTP_UNAUTHORIZED); |
|
1137 |
} |
|
1138 |
||
1139 |
// Read comments labeled "Failed Negotiate" for details. |
|
1140 |
boolean dontUseNegotiate = false; |
|
1141 |
Iterator iter = responses.multiValueIterator("WWW-Authenticate"); |
|
1142 |
while (iter.hasNext()) { |
|
1143 |
String value = ((String)iter.next()).trim(); |
|
1144 |
if (value.equalsIgnoreCase("Negotiate") || |
|
1145 |
value.equalsIgnoreCase("Kerberos")) { |
|
1146 |
if (!inNegotiate) { |
|
1147 |
inNegotiate = true; |
|
1148 |
} else { |
|
1149 |
dontUseNegotiate = true; |
|
1150 |
doingNTLM2ndStage = false; |
|
1151 |
serverAuthentication = null; |
|
1152 |
} |
|
1153 |
break; |
|
1154 |
} |
|
1155 |
} |
|
1156 |
||
1157 |
srvHdr = new AuthenticationHeader ( |
|
1158 |
"WWW-Authenticate", responses, |
|
1159 |
url.getHost().toLowerCase(), dontUseNegotiate |
|
1160 |
); |
|
1161 |
||
1162 |
String raw = srvHdr.raw(); |
|
1163 |
if (!doingNTLM2ndStage) { |
|
1164 |
if ((serverAuthentication != null)&& |
|
1165 |
!(serverAuthentication instanceof NTLMAuthentication)) { |
|
1166 |
if (serverAuthentication.isAuthorizationStale (raw)) { |
|
1167 |
/* we can retry with the current credentials */ |
|
1168 |
disconnectInternal(); |
|
1169 |
redirects++; |
|
1170 |
requests.set(serverAuthentication.getHeaderName(), |
|
1171 |
serverAuthentication.getHeaderValue(url, method)); |
|
1172 |
currentServerCredentials = serverAuthentication; |
|
1173 |
setCookieHeader(); |
|
1174 |
continue; |
|
1175 |
} else { |
|
1176 |
serverAuthentication.removeFromCache(); |
|
1177 |
} |
|
1178 |
} |
|
1179 |
serverAuthentication = getServerAuthentication(srvHdr); |
|
1180 |
currentServerCredentials = serverAuthentication; |
|
1181 |
||
1182 |
if (serverAuthentication != null) { |
|
1183 |
disconnectInternal(); |
|
1184 |
redirects++; // don't let things loop ad nauseum |
|
1185 |
setCookieHeader(); |
|
1186 |
continue; |
|
1187 |
} |
|
1188 |
} else { |
|
1189 |
reset (); |
|
1190 |
/* header not used for ntlm */ |
|
1191 |
if (!serverAuthentication.setHeaders(this, null, raw)) { |
|
1192 |
disconnectInternal(); |
|
1193 |
throw new IOException ("Authentication failure"); |
|
1194 |
} |
|
1195 |
doingNTLM2ndStage = false; |
|
1196 |
authObj = null; |
|
1197 |
setCookieHeader(); |
|
1198 |
continue; |
|
1199 |
} |
|
1200 |
} |
|
1201 |
// cache server authentication info |
|
1202 |
if (serverAuthentication != null) { |
|
1203 |
// cache auth info on success |
|
1204 |
if (!(serverAuthentication instanceof DigestAuthentication) || |
|
1205 |
(domain == null)) { |
|
1206 |
if (serverAuthentication instanceof BasicAuthentication) { |
|
1207 |
// check if the path is shorter than the existing entry |
|
1208 |
String npath = AuthenticationInfo.reducePath (url.getPath()); |
|
1209 |
String opath = serverAuthentication.path; |
|
1210 |
if (!opath.startsWith (npath) || npath.length() >= opath.length()) { |
|
1211 |
/* npath is longer, there must be a common root */ |
|
1212 |
npath = BasicAuthentication.getRootPath (opath, npath); |
|
1213 |
} |
|
1214 |
// remove the entry and create a new one |
|
1215 |
BasicAuthentication a = |
|
1216 |
(BasicAuthentication) serverAuthentication.clone(); |
|
1217 |
serverAuthentication.removeFromCache(); |
|
1218 |
a.path = npath; |
|
1219 |
serverAuthentication = a; |
|
1220 |
} |
|
1221 |
serverAuthentication.addToCache(); |
|
1222 |
} else { |
|
1223 |
// what we cache is based on the domain list in the request |
|
1224 |
DigestAuthentication srv = (DigestAuthentication) |
|
1225 |
serverAuthentication; |
|
1226 |
StringTokenizer tok = new StringTokenizer (domain," "); |
|
1227 |
String realm = srv.realm; |
|
1228 |
PasswordAuthentication pw = srv.pw; |
|
1229 |
digestparams = srv.params; |
|
1230 |
while (tok.hasMoreTokens()) { |
|
1231 |
String path = tok.nextToken(); |
|
1232 |
try { |
|
1233 |
/* path could be an abs_path or a complete URI */ |
|
1234 |
URL u = new URL (url, path); |
|
1235 |
DigestAuthentication d = new DigestAuthentication ( |
|
1236 |
false, u, realm, "Digest", pw, digestparams); |
|
1237 |
d.addToCache (); |
|
1238 |
} catch (Exception e) {} |
|
1239 |
} |
|
1240 |
} |
|
1241 |
} |
|
1242 |
||
1243 |
// some flags should be reset to its initialized form so that |
|
1244 |
// even after a redirect the necessary checks can still be |
|
1245 |
// preformed. |
|
1246 |
inNegotiate = false; |
|
1247 |
inNegotiateProxy = false; |
|
1248 |
||
1249 |
//serverAuthentication = null; |
|
1250 |
doingNTLMp2ndStage = false; |
|
1251 |
doingNTLM2ndStage = false; |
|
1252 |
if (!isUserServerAuth) |
|
1253 |
requests.remove("Authorization"); |
|
1254 |
if (!isUserProxyAuth) |
|
1255 |
requests.remove("Proxy-Authorization"); |
|
1256 |
||
1257 |
if (respCode == HTTP_OK) { |
|
1258 |
checkResponseCredentials (false); |
|
1259 |
} else { |
|
1260 |
needToCheck = false; |
|
1261 |
} |
|
1262 |
||
1263 |
// a flag need to clean |
|
1264 |
needToCheck = true; |
|
1265 |
||
1266 |
if (followRedirect()) { |
|
1267 |
/* if we should follow a redirect, then the followRedirects() |
|
1268 |
* method will disconnect() and re-connect us to the new |
|
1269 |
* location |
|
1270 |
*/ |
|
1271 |
redirects++; |
|
1272 |
||
1273 |
// redirecting HTTP response may have set cookie, so |
|
1274 |
// need to re-generate request header |
|
1275 |
setCookieHeader(); |
|
1276 |
||
1277 |
continue; |
|
1278 |
} |
|
1279 |
||
1280 |
try { |
|
1281 |
cl = Long.parseLong(responses.findValue("content-length")); |
|
1282 |
} catch (Exception exc) { }; |
|
1283 |
||
1284 |
if (method.equals("HEAD") || cl == 0 || |
|
1285 |
respCode == HTTP_NOT_MODIFIED || |
|
1286 |
respCode == HTTP_NO_CONTENT) { |
|
1287 |
||
1288 |
if (pi != null) { |
|
1289 |
pi.finishTracking(); |
|
1290 |
pi = null; |
|
1291 |
} |
|
1292 |
http.finished(); |
|
1293 |
http = null; |
|
1294 |
inputStream = new EmptyInputStream(); |
|
1295 |
connected = false; |
|
1296 |
} |
|
1297 |
||
1298 |
if (respCode == 200 || respCode == 203 || respCode == 206 || |
|
1299 |
respCode == 300 || respCode == 301 || respCode == 410) { |
|
1300 |
if (cacheHandler != null) { |
|
1301 |
// give cache a chance to save response in cache |
|
1302 |
URI uri = ParseUtil.toURI(url); |
|
1303 |
if (uri != null) { |
|
1304 |
URLConnection uconn = this; |
|
1305 |
if ("https".equalsIgnoreCase(uri.getScheme())) { |
|
1306 |
try { |
|
1307 |
// use reflection to get to the public |
|
1308 |
// HttpsURLConnection instance saved in |
|
1309 |
// DelegateHttpsURLConnection |
|
1310 |
uconn = (URLConnection)this.getClass().getField("httpsURLConnection").get(this); |
|
1311 |
} catch (IllegalAccessException iae) { |
|
1312 |
// ignored; use 'this' |
|
1313 |
} catch (NoSuchFieldException nsfe) { |
|
1314 |
// ignored; use 'this' |
|
1315 |
} |
|
1316 |
} |
|
1317 |
CacheRequest cacheRequest = |
|
1318 |
cacheHandler.put(uri, uconn); |
|
1319 |
if (cacheRequest != null && http != null) { |
|
1320 |
http.setCacheRequest(cacheRequest); |
|
1321 |
inputStream = new HttpInputStream(inputStream, cacheRequest); |
|
1322 |
} |
|
1323 |
} |
|
1324 |
} |
|
1325 |
} |
|
1326 |
||
1327 |
if (!(inputStream instanceof HttpInputStream)) { |
|
1328 |
inputStream = new HttpInputStream(inputStream); |
|
1329 |
} |
|
1330 |
||
1331 |
if (respCode >= 400) { |
|
1332 |
if (respCode == 404 || respCode == 410) { |
|
1333 |
throw new FileNotFoundException(url.toString()); |
|
1334 |
} else { |
|
1335 |
throw new java.io.IOException("Server returned HTTP" + |
|
1336 |
" response code: " + respCode + " for URL: " + |
|
1337 |
url.toString()); |
|
1338 |
} |
|
1339 |
} |
|
1340 |
poster = null; |
|
1341 |
strOutputStream = null; |
|
1342 |
return inputStream; |
|
1343 |
} while (redirects < maxRedirects); |
|
1344 |
||
1345 |
throw new ProtocolException("Server redirected too many " + |
|
1346 |
" times ("+ redirects + ")"); |
|
1347 |
} catch (RuntimeException e) { |
|
1348 |
disconnectInternal(); |
|
1349 |
rememberedException = e; |
|
1350 |
throw e; |
|
1351 |
} catch (IOException e) { |
|
1352 |
rememberedException = e; |
|
1353 |
||
1354 |
// buffer the error stream if bytes < 4k |
|
1355 |
// and it can be buffered within 1 second |
|
1356 |
String te = responses.findValue("Transfer-Encoding"); |
|
1357 |
if (http != null && http.isKeepingAlive() && enableESBuffer && |
|
1358 |
(cl > 0 || (te != null && te.equalsIgnoreCase("chunked")))) { |
|
1359 |
errorStream = ErrorStream.getErrorStream(inputStream, cl, http); |
|
1360 |
} |
|
1361 |
throw e; |
|
1362 |
} finally { |
|
1363 |
if (respCode == HTTP_PROXY_AUTH && proxyAuthentication != null) { |
|
1364 |
proxyAuthentication.endAuthRequest(); |
|
1365 |
} |
|
1366 |
else if (respCode == HTTP_UNAUTHORIZED && serverAuthentication != null) { |
|
1367 |
serverAuthentication.endAuthRequest(); |
|
1368 |
} |
|
1369 |
} |
|
1370 |
} |
|
1371 |
||
1372 |
/* |
|
1373 |
* Creates a chained exception that has the same type as |
|
1374 |
* original exception and with the same message. Right now, |
|
1375 |
* there is no convenient APIs for doing so. |
|
1376 |
*/ |
|
51 | 1377 |
private IOException getChainedException(final IOException rememberedException) { |
2 | 1378 |
try { |
51 | 1379 |
final Object[] args = { rememberedException.getMessage() }; |
1380 |
IOException chainedException = |
|
1381 |
java.security.AccessController.doPrivileged( |
|
1382 |
new java.security.PrivilegedExceptionAction<IOException>() { |
|
1383 |
public IOException run() throws Exception { |
|
1384 |
return (IOException) |
|
1385 |
rememberedException.getClass() |
|
1386 |
.getConstructor(new Class[] { String.class }) |
|
1387 |
.newInstance(args); |
|
2 | 1388 |
} |
1389 |
}); |
|
51 | 1390 |
chainedException.initCause(rememberedException); |
2 | 1391 |
return chainedException; |
1392 |
} catch (Exception ignored) { |
|
1393 |
return rememberedException; |
|
1394 |
} |
|
1395 |
} |
|
1396 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
1397 |
@Override |
2 | 1398 |
public InputStream getErrorStream() { |
1399 |
if (connected && responseCode >= 400) { |
|
1400 |
// Client Error 4xx and Server Error 5xx |
|
1401 |
if (errorStream != null) { |
|
1402 |
return errorStream; |
|
1403 |
} else if (inputStream != null) { |
|
1404 |
return inputStream; |
|
1405 |
} |
|
1406 |
} |
|
1407 |
return null; |
|
1408 |
} |
|
1409 |
||
1410 |
/** |
|
1411 |
* set or reset proxy authentication info in request headers |
|
1412 |
* after receiving a 407 error. In the case of NTLM however, |
|
1413 |
* receiving a 407 is normal and we just skip the stale check |
|
1414 |
* because ntlm does not support this feature. |
|
1415 |
*/ |
|
1416 |
private AuthenticationInfo |
|
1417 |
resetProxyAuthentication(AuthenticationInfo proxyAuthentication, AuthenticationHeader auth) { |
|
1418 |
if ((proxyAuthentication != null )&& ! (proxyAuthentication instanceof |
|
1419 |
NTLMAuthentication)) { |
|
1420 |
String raw = auth.raw(); |
|
1421 |
if (proxyAuthentication.isAuthorizationStale (raw)) { |
|
1422 |
/* we can retry with the current credentials */ |
|
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1423 |
String value; |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1424 |
if (tunnelState() == TunnelState.SETUP && |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1425 |
proxyAuthentication instanceof DigestAuthentication) { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1426 |
value = ((DigestAuthentication)proxyAuthentication) |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1427 |
.getHeaderValue(connectRequestURI(url), HTTP_CONNECT); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1428 |
} else { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1429 |
value = proxyAuthentication.getHeaderValue(url, method); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1430 |
} |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1431 |
requests.set(proxyAuthentication.getHeaderName(), value); |
2 | 1432 |
currentProxyCredentials = proxyAuthentication; |
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1433 |
return proxyAuthentication; |
2 | 1434 |
} else { |
1435 |
proxyAuthentication.removeFromCache(); |
|
1436 |
} |
|
1437 |
} |
|
1438 |
proxyAuthentication = getHttpProxyAuthentication(auth); |
|
1439 |
currentProxyCredentials = proxyAuthentication; |
|
1440 |
return proxyAuthentication; |
|
1441 |
} |
|
1442 |
||
1443 |
/** |
|
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1444 |
* Returns the tunnel state. |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1445 |
* |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1446 |
* @return the state |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1447 |
*/ |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1448 |
TunnelState tunnelState() { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1449 |
return tunnelState; |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1450 |
} |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1451 |
|
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1452 |
/** |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1453 |
* Set the tunneling status. |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1454 |
* |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1455 |
* @param the state |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1456 |
*/ |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1457 |
void setTunnelState(TunnelState tunnelState) { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1458 |
this.tunnelState = tunnelState; |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1459 |
} |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1460 |
|
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1461 |
/** |
2 | 1462 |
* establish a tunnel through proxy server |
1463 |
*/ |
|
1464 |
public synchronized void doTunneling() throws IOException { |
|
1465 |
int retryTunnel = 0; |
|
1466 |
String statusLine = ""; |
|
1467 |
int respCode = 0; |
|
1468 |
AuthenticationInfo proxyAuthentication = null; |
|
1469 |
String proxyHost = null; |
|
1470 |
int proxyPort = -1; |
|
1471 |
||
1472 |
// save current requests so that they can be restored after tunnel is setup. |
|
1473 |
MessageHeader savedRequests = requests; |
|
1474 |
requests = new MessageHeader(); |
|
1475 |
||
1476 |
// Read comments labeled "Failed Negotiate" for details. |
|
1477 |
boolean inNegotiateProxy = false; |
|
1478 |
||
1479 |
try { |
|
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1480 |
/* Actively setting up a tunnel */ |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1481 |
setTunnelState(TunnelState.SETUP); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1482 |
|
2 | 1483 |
do { |
1484 |
if (!checkReuseConnection()) { |
|
1485 |
proxiedConnect(url, proxyHost, proxyPort, false); |
|
1486 |
} |
|
1487 |
// send the "CONNECT" request to establish a tunnel |
|
1488 |
// through proxy server |
|
1489 |
sendCONNECTRequest(); |
|
1490 |
responses.reset(); |
|
1491 |
||
1492 |
// There is no need to track progress in HTTP Tunneling, |
|
1493 |
// so ProgressSource is null. |
|
1494 |
http.parseHTTP(responses, null, this); |
|
1495 |
||
478
5adf3e3f1ff3
6659779: HttpURLConnections logger should log tunnel requests
chegar
parents:
94
diff
changeset
|
1496 |
/* Log the response to the CONNECT */ |
5adf3e3f1ff3
6659779: HttpURLConnections logger should log tunnel requests
chegar
parents:
94
diff
changeset
|
1497 |
logger.fine(responses.toString()); |
5adf3e3f1ff3
6659779: HttpURLConnections logger should log tunnel requests
chegar
parents:
94
diff
changeset
|
1498 |
|
2 | 1499 |
statusLine = responses.getValue(0); |
1500 |
StringTokenizer st = new StringTokenizer(statusLine); |
|
1501 |
st.nextToken(); |
|
1502 |
respCode = Integer.parseInt(st.nextToken().trim()); |
|
1503 |
if (respCode == HTTP_PROXY_AUTH) { |
|
1504 |
// Read comments labeled "Failed Negotiate" for details. |
|
1505 |
boolean dontUseNegotiate = false; |
|
1506 |
Iterator iter = responses.multiValueIterator("Proxy-Authenticate"); |
|
1507 |
while (iter.hasNext()) { |
|
1508 |
String value = ((String)iter.next()).trim(); |
|
1509 |
if (value.equalsIgnoreCase("Negotiate") || |
|
1510 |
value.equalsIgnoreCase("Kerberos")) { |
|
1511 |
if (!inNegotiateProxy) { |
|
1512 |
inNegotiateProxy = true; |
|
1513 |
} else { |
|
1514 |
dontUseNegotiate = true; |
|
1515 |
doingNTLMp2ndStage = false; |
|
1516 |
proxyAuthentication = null; |
|
1517 |
} |
|
1518 |
break; |
|
1519 |
} |
|
1520 |
} |
|
1521 |
||
1522 |
AuthenticationHeader authhdr = new AuthenticationHeader ( |
|
1523 |
"Proxy-Authenticate", responses, |
|
1524 |
http.getProxyHostUsed(), dontUseNegotiate |
|
1525 |
); |
|
1526 |
if (!doingNTLMp2ndStage) { |
|
1527 |
proxyAuthentication = |
|
1528 |
resetProxyAuthentication(proxyAuthentication, authhdr); |
|
1529 |
if (proxyAuthentication != null) { |
|
1530 |
proxyHost = http.getProxyHostUsed(); |
|
1531 |
proxyPort = http.getProxyPortUsed(); |
|
1532 |
disconnectInternal(); |
|
1533 |
retryTunnel++; |
|
1534 |
continue; |
|
1535 |
} |
|
1536 |
} else { |
|
1537 |
String raw = responses.findValue ("Proxy-Authenticate"); |
|
1538 |
reset (); |
|
1539 |
if (!proxyAuthentication.setHeaders(this, |
|
1540 |
authhdr.headerParser(), raw)) { |
|
1541 |
proxyHost = http.getProxyHostUsed(); |
|
1542 |
proxyPort = http.getProxyPortUsed(); |
|
1543 |
disconnectInternal(); |
|
1544 |
throw new IOException ("Authentication failure"); |
|
1545 |
} |
|
1546 |
authObj = null; |
|
1547 |
doingNTLMp2ndStage = false; |
|
1548 |
continue; |
|
1549 |
} |
|
1550 |
} |
|
1551 |
// cache proxy authentication info |
|
1552 |
if (proxyAuthentication != null) { |
|
1553 |
// cache auth info on success, domain header not relevant. |
|
1554 |
proxyAuthentication.addToCache(); |
|
1555 |
} |
|
1556 |
||
1557 |
if (respCode == HTTP_OK) { |
|
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1558 |
setTunnelState(TunnelState.TUNNELING); |
2 | 1559 |
break; |
1560 |
} |
|
1561 |
// we don't know how to deal with other response code |
|
1562 |
// so disconnect and report error |
|
1563 |
disconnectInternal(); |
|
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1564 |
setTunnelState(TunnelState.NONE); |
2 | 1565 |
break; |
1566 |
} while (retryTunnel < maxRedirects); |
|
1567 |
||
1568 |
if (retryTunnel >= maxRedirects || (respCode != HTTP_OK)) { |
|
1569 |
throw new IOException("Unable to tunnel through proxy."+ |
|
1570 |
" Proxy returns \"" + |
|
1571 |
statusLine + "\""); |
|
1572 |
} |
|
1573 |
} finally { |
|
1574 |
if (respCode == HTTP_PROXY_AUTH && proxyAuthentication != null) { |
|
1575 |
proxyAuthentication.endAuthRequest(); |
|
1576 |
} |
|
1577 |
} |
|
1578 |
||
1579 |
// restore original request headers |
|
1580 |
requests = savedRequests; |
|
1581 |
||
1582 |
// reset responses |
|
1583 |
responses.reset(); |
|
1584 |
} |
|
1585 |
||
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1586 |
static String connectRequestURI(URL url) { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1587 |
String host = url.getHost(); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1588 |
int port = url.getPort(); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1589 |
port = port != -1 ? port : url.getDefaultPort(); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1590 |
|
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1591 |
return host + ":" + port; |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1592 |
} |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1593 |
|
2 | 1594 |
/** |
1595 |
* send a CONNECT request for establishing a tunnel to proxy server |
|
1596 |
*/ |
|
1597 |
private void sendCONNECTRequest() throws IOException { |
|
1598 |
int port = url.getPort(); |
|
1599 |
||
1600 |
// setRequests == true indicates the std. request headers |
|
1601 |
// have been set in (previous) requests. |
|
1602 |
// so the first one must be the http method (GET, etc.). |
|
1603 |
// we need to set it to CONNECT soon, remove this one first. |
|
1604 |
// otherwise, there may have 2 http methods in headers |
|
1605 |
if (setRequests) requests.set(0, null, null); |
|
1606 |
||
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1607 |
requests.prepend(HTTP_CONNECT + " " + connectRequestURI(url) |
2 | 1608 |
+ " " + httpVersion, null); |
1609 |
requests.setIfNotSet("User-Agent", userAgent); |
|
1610 |
||
1611 |
String host = url.getHost(); |
|
1612 |
if (port != -1 && port != url.getDefaultPort()) { |
|
1613 |
host += ":" + String.valueOf(port); |
|
1614 |
} |
|
1615 |
requests.setIfNotSet("Host", host); |
|
1616 |
||
1617 |
// Not really necessary for a tunnel, but can't hurt |
|
1618 |
requests.setIfNotSet("Accept", acceptString); |
|
1619 |
||
1620 |
setPreemptiveProxyAuthentication(requests); |
|
478
5adf3e3f1ff3
6659779: HttpURLConnections logger should log tunnel requests
chegar
parents:
94
diff
changeset
|
1621 |
|
5adf3e3f1ff3
6659779: HttpURLConnections logger should log tunnel requests
chegar
parents:
94
diff
changeset
|
1622 |
/* Log the CONNECT request */ |
5adf3e3f1ff3
6659779: HttpURLConnections logger should log tunnel requests
chegar
parents:
94
diff
changeset
|
1623 |
logger.fine(requests.toString()); |
5adf3e3f1ff3
6659779: HttpURLConnections logger should log tunnel requests
chegar
parents:
94
diff
changeset
|
1624 |
|
2 | 1625 |
http.writeRequests(requests, null); |
1626 |
// remove CONNECT header |
|
1627 |
requests.set(0, null, null); |
|
1628 |
} |
|
1629 |
||
1630 |
/** |
|
1631 |
* Sets pre-emptive proxy authentication in header |
|
1632 |
*/ |
|
1633 |
private void setPreemptiveProxyAuthentication(MessageHeader requests) { |
|
1634 |
AuthenticationInfo pauth |
|
1635 |
= AuthenticationInfo.getProxyAuth(http.getProxyHostUsed(), |
|
1636 |
http.getProxyPortUsed()); |
|
1637 |
if (pauth != null && pauth.supportsPreemptiveAuthorization()) { |
|
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1638 |
String value; |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1639 |
if (tunnelState() == TunnelState.SETUP && |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1640 |
pauth instanceof DigestAuthentication) { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1641 |
value = ((DigestAuthentication)pauth) |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1642 |
.getHeaderValue(connectRequestURI(url), HTTP_CONNECT); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1643 |
} else { |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1644 |
value = pauth.getHeaderValue(url, method); |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1645 |
} |
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1646 |
|
2 | 1647 |
// Sets "Proxy-authorization" |
479
c6ddcfc7ff4d
6687282: URLConnection for HTTPS connection through Proxy w/ Digest Authentication gives 400 Bad Request
chegar
parents:
478
diff
changeset
|
1648 |
requests.set(pauth.getHeaderName(), value); |
2 | 1649 |
currentProxyCredentials = pauth; |
1650 |
} |
|
1651 |
} |
|
1652 |
||
1653 |
/** |
|
1654 |
* Gets the authentication for an HTTP proxy, and applies it to |
|
1655 |
* the connection. |
|
1656 |
*/ |
|
1657 |
private AuthenticationInfo getHttpProxyAuthentication (AuthenticationHeader authhdr) { |
|
1658 |
/* get authorization from authenticator */ |
|
1659 |
AuthenticationInfo ret = null; |
|
1660 |
String raw = authhdr.raw(); |
|
1661 |
String host = http.getProxyHostUsed(); |
|
1662 |
int port = http.getProxyPortUsed(); |
|
1663 |
if (host != null && authhdr.isPresent()) { |
|
1664 |
HeaderParser p = authhdr.headerParser(); |
|
1665 |
String realm = p.findValue("realm"); |
|
1666 |
String scheme = authhdr.scheme(); |
|
1667 |
char schemeID; |
|
1668 |
if ("basic".equalsIgnoreCase(scheme)) { |
|
1669 |
schemeID = BasicAuthentication.BASIC_AUTH; |
|
1670 |
} else if ("digest".equalsIgnoreCase(scheme)) { |
|
1671 |
schemeID = DigestAuthentication.DIGEST_AUTH; |
|
1672 |
} else if ("ntlm".equalsIgnoreCase(scheme)) { |
|
1673 |
schemeID = NTLMAuthentication.NTLM_AUTH; |
|
1674 |
doingNTLMp2ndStage = true; |
|
1675 |
} else if ("Kerberos".equalsIgnoreCase(scheme)) { |
|
1676 |
schemeID = NegotiateAuthentication.KERBEROS_AUTH; |
|
1677 |
doingNTLMp2ndStage = true; |
|
1678 |
} else if ("Negotiate".equalsIgnoreCase(scheme)) { |
|
1679 |
schemeID = NegotiateAuthentication.NEGOTIATE_AUTH; |
|
1680 |
doingNTLMp2ndStage = true; |
|
1681 |
} else { |
|
1682 |
schemeID = 0; |
|
1683 |
} |
|
1684 |
if (realm == null) |
|
1685 |
realm = ""; |
|
1686 |
ret = AuthenticationInfo.getProxyAuth(host, port, realm, schemeID); |
|
1687 |
if (ret == null) { |
|
1688 |
if (schemeID == BasicAuthentication.BASIC_AUTH) { |
|
1689 |
InetAddress addr = null; |
|
1690 |
try { |
|
1691 |
final String finalHost = host; |
|
51 | 1692 |
addr = java.security.AccessController.doPrivileged( |
1693 |
new java.security.PrivilegedExceptionAction<InetAddress>() { |
|
1694 |
public InetAddress run() |
|
2 | 1695 |
throws java.net.UnknownHostException { |
1696 |
return InetAddress.getByName(finalHost); |
|
1697 |
} |
|
1698 |
}); |
|
1699 |
} catch (java.security.PrivilegedActionException ignored) { |
|
1700 |
// User will have an unknown host. |
|
1701 |
} |
|
1702 |
PasswordAuthentication a = |
|
1703 |
privilegedRequestPasswordAuthentication( |
|
1704 |
host, addr, port, "http", |
|
1705 |
realm, scheme, url, RequestorType.PROXY); |
|
1706 |
if (a != null) { |
|
1707 |
ret = new BasicAuthentication(true, host, port, realm, a); |
|
1708 |
} |
|
1709 |
} else if (schemeID == DigestAuthentication.DIGEST_AUTH) { |
|
1710 |
PasswordAuthentication a = |
|
1711 |
privilegedRequestPasswordAuthentication( |
|
1712 |
host, null, port, url.getProtocol(), |
|
1713 |
realm, scheme, url, RequestorType.PROXY); |
|
1714 |
if (a != null) { |
|
1715 |
DigestAuthentication.Parameters params = |
|
1716 |
new DigestAuthentication.Parameters(); |
|
1717 |
ret = new DigestAuthentication(true, host, port, realm, |
|
1718 |
scheme, a, params); |
|
1719 |
} |
|
1720 |
} else if (schemeID == NTLMAuthentication.NTLM_AUTH) { |
|
1721 |
PasswordAuthentication a = null; |
|
1722 |
if (!tryTransparentNTLMProxy) { |
|
1723 |
a = privilegedRequestPasswordAuthentication( |
|
1724 |
host, null, port, url.getProtocol(), |
|
1725 |
"", scheme, url, RequestorType.PROXY); |
|
1726 |
} |
|
1727 |
/* If we are not trying transparent authentication then |
|
1728 |
* we need to have a PasswordAuthentication instance. For |
|
1729 |
* transparent authentication (Windows only) the username |
|
1730 |
* and password will be picked up from the current logged |
|
1731 |
* on users credentials. |
|
1732 |
*/ |
|
1733 |
if (tryTransparentNTLMProxy || |
|
1734 |
(!tryTransparentNTLMProxy && a != null)) { |
|
1735 |
ret = new NTLMAuthentication(true, host, port, a); |
|
1736 |
} |
|
1737 |
||
1738 |
tryTransparentNTLMProxy = false; |
|
1739 |
} else if (schemeID == NegotiateAuthentication.NEGOTIATE_AUTH) { |
|
1740 |
ret = new NegotiateAuthentication(true, host, port, null, "Negotiate"); |
|
1741 |
} else if (schemeID == NegotiateAuthentication.KERBEROS_AUTH) { |
|
1742 |
ret = new NegotiateAuthentication(true, host, port, null, "Kerberos"); |
|
1743 |
} |
|
1744 |
} |
|
1745 |
// For backwards compatibility, we also try defaultAuth |
|
1746 |
// REMIND: Get rid of this for JDK2.0. |
|
1747 |
||
1748 |
if (ret == null && defaultAuth != null |
|
1749 |
&& defaultAuth.schemeSupported(scheme)) { |
|
1750 |
try { |
|
1751 |
URL u = new URL("http", host, port, "/"); |
|
1752 |
String a = defaultAuth.authString(u, scheme, realm); |
|
1753 |
if (a != null) { |
|
1754 |
ret = new BasicAuthentication (true, host, port, realm, a); |
|
1755 |
// not in cache by default - cache on success |
|
1756 |
} |
|
1757 |
} catch (java.net.MalformedURLException ignored) { |
|
1758 |
} |
|
1759 |
} |
|
1760 |
if (ret != null) { |
|
1761 |
if (!ret.setHeaders(this, p, raw)) { |
|
1762 |
ret = null; |
|
1763 |
} |
|
1764 |
} |
|
1765 |
} |
|
1766 |
return ret; |
|
1767 |
} |
|
1768 |
||
1769 |
/** |
|
1770 |
* Gets the authentication for an HTTP server, and applies it to |
|
1771 |
* the connection. |
|
1772 |
* @param authHdr the AuthenticationHeader which tells what auth scheme is |
|
1773 |
* prefered. |
|
1774 |
*/ |
|
1775 |
private AuthenticationInfo getServerAuthentication (AuthenticationHeader authhdr) { |
|
1776 |
/* get authorization from authenticator */ |
|
1777 |
AuthenticationInfo ret = null; |
|
1778 |
String raw = authhdr.raw(); |
|
1779 |
/* When we get an NTLM auth from cache, don't set any special headers */ |
|
1780 |
if (authhdr.isPresent()) { |
|
1781 |
HeaderParser p = authhdr.headerParser(); |
|
1782 |
String realm = p.findValue("realm"); |
|
1783 |
String scheme = authhdr.scheme(); |
|
1784 |
char schemeID; |
|
1785 |
if ("basic".equalsIgnoreCase(scheme)) { |
|
1786 |
schemeID = BasicAuthentication.BASIC_AUTH; |
|
1787 |
} else if ("digest".equalsIgnoreCase(scheme)) { |
|
1788 |
schemeID = DigestAuthentication.DIGEST_AUTH; |
|
1789 |
} else if ("ntlm".equalsIgnoreCase(scheme)) { |
|
1790 |
schemeID = NTLMAuthentication.NTLM_AUTH; |
|
1791 |
doingNTLM2ndStage = true; |
|
1792 |
} else if ("Kerberos".equalsIgnoreCase(scheme)) { |
|
1793 |
schemeID = NegotiateAuthentication.KERBEROS_AUTH; |
|
1794 |
doingNTLM2ndStage = true; |
|
1795 |
} else if ("Negotiate".equalsIgnoreCase(scheme)) { |
|
1796 |
schemeID = NegotiateAuthentication.NEGOTIATE_AUTH; |
|
1797 |
doingNTLM2ndStage = true; |
|
1798 |
} else { |
|
1799 |
schemeID = 0; |
|
1800 |
} |
|
1801 |
domain = p.findValue ("domain"); |
|
1802 |
if (realm == null) |
|
1803 |
realm = ""; |
|
1804 |
ret = AuthenticationInfo.getServerAuth(url, realm, schemeID); |
|
1805 |
InetAddress addr = null; |
|
1806 |
if (ret == null) { |
|
1807 |
try { |
|
1808 |
addr = InetAddress.getByName(url.getHost()); |
|
1809 |
} catch (java.net.UnknownHostException ignored) { |
|
1810 |
// User will have addr = null |
|
1811 |
} |
|
1812 |
} |
|
1813 |
// replacing -1 with default port for a protocol |
|
1814 |
int port = url.getPort(); |
|
1815 |
if (port == -1) { |
|
1816 |
port = url.getDefaultPort(); |
|
1817 |
} |
|
1818 |
if (ret == null) { |
|
1819 |
if (schemeID == NegotiateAuthentication.KERBEROS_AUTH) { |
|
1820 |
URL url1; |
|
1821 |
try { |
|
1822 |
url1 = new URL (url, "/"); /* truncate the path */ |
|
1823 |
} catch (Exception e) { |
|
1824 |
url1 = url; |
|
1825 |
} |
|
1826 |
ret = new NegotiateAuthentication(false, url1, null, "Kerberos"); |
|
1827 |
} |
|
1828 |
if (schemeID == NegotiateAuthentication.NEGOTIATE_AUTH) { |
|
1829 |
URL url1; |
|
1830 |
try { |
|
1831 |
url1 = new URL (url, "/"); /* truncate the path */ |
|
1832 |
} catch (Exception e) { |
|
1833 |
url1 = url; |
|
1834 |
} |
|
1835 |
ret = new NegotiateAuthentication(false, url1, null, "Negotiate"); |
|
1836 |
} |
|
1837 |
if (schemeID == BasicAuthentication.BASIC_AUTH) { |
|
1838 |
PasswordAuthentication a = |
|
1839 |
privilegedRequestPasswordAuthentication( |
|
1840 |
url.getHost(), addr, port, url.getProtocol(), |
|
1841 |
realm, scheme, url, RequestorType.SERVER); |
|
1842 |
if (a != null) { |
|
1843 |
ret = new BasicAuthentication(false, url, realm, a); |
|
1844 |
} |
|
1845 |
} |
|
1846 |
||
1847 |
if (schemeID == DigestAuthentication.DIGEST_AUTH) { |
|
1848 |
PasswordAuthentication a = |
|
1849 |
privilegedRequestPasswordAuthentication( |
|
1850 |
url.getHost(), addr, port, url.getProtocol(), |
|
1851 |
realm, scheme, url, RequestorType.SERVER); |
|
1852 |
if (a != null) { |
|
1853 |
digestparams = new DigestAuthentication.Parameters(); |
|
1854 |
ret = new DigestAuthentication(false, url, realm, scheme, a, digestparams); |
|
1855 |
} |
|
1856 |
} |
|
1857 |
||
1858 |
if (schemeID == NTLMAuthentication.NTLM_AUTH) { |
|
1859 |
URL url1; |
|
1860 |
try { |
|
1861 |
url1 = new URL (url, "/"); /* truncate the path */ |
|
1862 |
} catch (Exception e) { |
|
1863 |
url1 = url; |
|
1864 |
} |
|
1865 |
PasswordAuthentication a = null; |
|
1866 |
if (!tryTransparentNTLMServer) { |
|
1867 |
a = privilegedRequestPasswordAuthentication( |
|
1868 |
url.getHost(), addr, port, url.getProtocol(), |
|
1869 |
"", scheme, url, RequestorType.SERVER); |
|
1870 |
} |
|
1871 |
||
1872 |
/* If we are not trying transparent authentication then |
|
1873 |
* we need to have a PasswordAuthentication instance. For |
|
1874 |
* transparent authentication (Windows only) the username |
|
1875 |
* and password will be picked up from the current logged |
|
1876 |
* on users credentials. |
|
1877 |
*/ |
|
1878 |
if (tryTransparentNTLMServer || |
|
1879 |
(!tryTransparentNTLMServer && a != null)) { |
|
1880 |
ret = new NTLMAuthentication(false, url1, a); |
|
1881 |
} |
|
1882 |
||
1883 |
tryTransparentNTLMServer = false; |
|
1884 |
} |
|
1885 |
} |
|
1886 |
||
1887 |
// For backwards compatibility, we also try defaultAuth |
|
1888 |
// REMIND: Get rid of this for JDK2.0. |
|
1889 |
||
1890 |
if (ret == null && defaultAuth != null |
|
1891 |
&& defaultAuth.schemeSupported(scheme)) { |
|
1892 |
String a = defaultAuth.authString(url, scheme, realm); |
|
1893 |
if (a != null) { |
|
1894 |
ret = new BasicAuthentication (false, url, realm, a); |
|
1895 |
// not in cache by default - cache on success |
|
1896 |
} |
|
1897 |
} |
|
1898 |
||
1899 |
if (ret != null ) { |
|
1900 |
if (!ret.setHeaders(this, p, raw)) { |
|
1901 |
ret = null; |
|
1902 |
} |
|
1903 |
} |
|
1904 |
} |
|
1905 |
return ret; |
|
1906 |
} |
|
1907 |
||
1908 |
/* inclose will be true if called from close(), in which case we |
|
1909 |
* force the call to check because this is the last chance to do so. |
|
1910 |
* If not in close(), then the authentication info could arrive in a trailer |
|
1911 |
* field, which we have not read yet. |
|
1912 |
*/ |
|
1913 |
private void checkResponseCredentials (boolean inClose) throws IOException { |
|
1914 |
try { |
|
1915 |
if (!needToCheck) |
|
1916 |
return; |
|
1917 |
if (validateProxy && currentProxyCredentials != null) { |
|
1918 |
String raw = responses.findValue ("Proxy-Authentication-Info"); |
|
1919 |
if (inClose || (raw != null)) { |
|
1920 |
currentProxyCredentials.checkResponse (raw, method, url); |
|
1921 |
currentProxyCredentials = null; |
|
1922 |
} |
|
1923 |
} |
|
1924 |
if (validateServer && currentServerCredentials != null) { |
|
1925 |
String raw = responses.findValue ("Authentication-Info"); |
|
1926 |
if (inClose || (raw != null)) { |
|
1927 |
currentServerCredentials.checkResponse (raw, method, url); |
|
1928 |
currentServerCredentials = null; |
|
1929 |
} |
|
1930 |
} |
|
1931 |
if ((currentServerCredentials==null) && (currentProxyCredentials == null)) { |
|
1932 |
needToCheck = false; |
|
1933 |
} |
|
1934 |
} catch (IOException e) { |
|
1935 |
disconnectInternal(); |
|
1936 |
connected = false; |
|
1937 |
throw e; |
|
1938 |
} |
|
1939 |
} |
|
1940 |
||
1941 |
/* Tells us whether to follow a redirect. If so, it |
|
1942 |
* closes the connection (break any keep-alive) and |
|
1943 |
* resets the url, re-connects, and resets the request |
|
1944 |
* property. |
|
1945 |
*/ |
|
1946 |
private boolean followRedirect() throws IOException { |
|
1947 |
if (!getInstanceFollowRedirects()) { |
|
1948 |
return false; |
|
1949 |
} |
|
1950 |
||
1951 |
int stat = getResponseCode(); |
|
1952 |
if (stat < 300 || stat > 307 || stat == 306 |
|
1953 |
|| stat == HTTP_NOT_MODIFIED) { |
|
1954 |
return false; |
|
1955 |
} |
|
1956 |
String loc = getHeaderField("Location"); |
|
1957 |
if (loc == null) { |
|
1958 |
/* this should be present - if not, we have no choice |
|
1959 |
* but to go forward w/ the response we got |
|
1960 |
*/ |
|
1961 |
return false; |
|
1962 |
} |
|
1963 |
URL locUrl; |
|
1964 |
try { |
|
1965 |
locUrl = new URL(loc); |
|
1966 |
if (!url.getProtocol().equalsIgnoreCase(locUrl.getProtocol())) { |
|
1967 |
return false; |
|
1968 |
} |
|
1969 |
||
1970 |
} catch (MalformedURLException mue) { |
|
1971 |
// treat loc as a relative URI to conform to popular browsers |
|
1972 |
locUrl = new URL(url, loc); |
|
1973 |
} |
|
1974 |
disconnectInternal(); |
|
1975 |
if (streaming()) { |
|
1976 |
throw new HttpRetryException (RETRY_MSG3, stat, loc); |
|
1977 |
} |
|
1978 |
||
1979 |
// clear out old response headers!!!! |
|
1980 |
responses = new MessageHeader(); |
|
1981 |
if (stat == HTTP_USE_PROXY) { |
|
1982 |
/* This means we must re-request the resource through the |
|
1983 |
* proxy denoted in the "Location:" field of the response. |
|
1984 |
* Judging by the spec, the string in the Location header |
|
1985 |
* _should_ denote a URL - let's hope for "http://my.proxy.org" |
|
1986 |
* Make a new HttpClient to the proxy, using HttpClient's |
|
1987 |
* Instance-specific proxy fields, but note we're still fetching |
|
1988 |
* the same URL. |
|
1989 |
*/ |
|
1990 |
String proxyHost = locUrl.getHost(); |
|
1991 |
int proxyPort = locUrl.getPort(); |
|
1992 |
||
1993 |
SecurityManager security = System.getSecurityManager(); |
|
1994 |
if (security != null) { |
|
1995 |
security.checkConnect(proxyHost, proxyPort); |
|
1996 |
} |
|
1997 |
||
1998 |
setProxiedClient (url, proxyHost, proxyPort); |
|
1999 |
requests.set(0, method + " " + http.getURLFile()+" " + |
|
2000 |
httpVersion, null); |
|
2001 |
connected = true; |
|
2002 |
} else { |
|
2003 |
// maintain previous headers, just change the name |
|
2004 |
// of the file we're getting |
|
2005 |
url = locUrl; |
|
2006 |
if (method.equals("POST") && !Boolean.getBoolean("http.strictPostRedirect") && (stat!=307)) { |
|
2007 |
/* The HTTP/1.1 spec says that a redirect from a POST |
|
2008 |
* *should not* be immediately turned into a GET, and |
|
2009 |
* that some HTTP/1.0 clients incorrectly did this. |
|
2010 |
* Correct behavior redirects a POST to another POST. |
|
2011 |
* Unfortunately, since most browsers have this incorrect |
|
2012 |
* behavior, the web works this way now. Typical usage |
|
2013 |
* seems to be: |
|
2014 |
* POST a login code or passwd to a web page. |
|
2015 |
* after validation, the server redirects to another |
|
2016 |
* (welcome) page |
|
2017 |
* The second request is (erroneously) expected to be GET |
|
2018 |
* |
|
2019 |
* We will do the incorrect thing (POST-->GET) by default. |
|
2020 |
* We will provide the capability to do the "right" thing |
|
2021 |
* (POST-->POST) by a system property, "http.strictPostRedirect=true" |
|
2022 |
*/ |
|
2023 |
||
2024 |
requests = new MessageHeader(); |
|
2025 |
setRequests = false; |
|
2026 |
setRequestMethod("GET"); |
|
2027 |
poster = null; |
|
2028 |
if (!checkReuseConnection()) |
|
2029 |
connect(); |
|
2030 |
} else { |
|
2031 |
if (!checkReuseConnection()) |
|
2032 |
connect(); |
|
2033 |
/* Even after a connect() call, http variable still can be |
|
2034 |
* null, if a ResponseCache has been installed and it returns |
|
2035 |
* a non-null CacheResponse instance. So check nullity before using it. |
|
2036 |
* |
|
2037 |
* And further, if http is null, there's no need to do anything |
|
2038 |
* about request headers because successive http session will use |
|
2039 |
* cachedInputStream/cachedHeaders anyway, which is returned by |
|
2040 |
* CacheResponse. |
|
2041 |
*/ |
|
2042 |
if (http != null) { |
|
2043 |
requests.set(0, method + " " + http.getURLFile()+" " + |
|
2044 |
httpVersion, null); |
|
2045 |
int port = url.getPort(); |
|
2046 |
String host = url.getHost(); |
|
2047 |
if (port != -1 && port != url.getDefaultPort()) { |
|
2048 |
host += ":" + String.valueOf(port); |
|
2049 |
} |
|
2050 |
requests.set("Host", host); |
|
2051 |
} |
|
2052 |
} |
|
2053 |
} |
|
2054 |
return true; |
|
2055 |
} |
|
2056 |
||
2057 |
/* dummy byte buffer for reading off socket prior to closing */ |
|
2058 |
byte[] cdata = new byte [128]; |
|
2059 |
||
2060 |
/** |
|
2061 |
* Reset (without disconnecting the TCP conn) in order to do another transaction with this instance |
|
2062 |
*/ |
|
2063 |
private void reset() throws IOException { |
|
2064 |
http.reuse = true; |
|
2065 |
/* must save before calling close */ |
|
2066 |
reuseClient = http; |
|
2067 |
InputStream is = http.getInputStream(); |
|
2068 |
if (!method.equals("HEAD")) { |
|
2069 |
try { |
|
2070 |
/* we want to read the rest of the response without using the |
|
2071 |
* hurry mechanism, because that would close the connection |
|
2072 |
* if everything is not available immediately |
|
2073 |
*/ |
|
2074 |
if ((is instanceof ChunkedInputStream) || |
|
2075 |
(is instanceof MeteredStream)) { |
|
2076 |
/* reading until eof will not block */ |
|
2077 |
while (is.read (cdata) > 0) {} |
|
2078 |
} else { |
|
2079 |
/* raw stream, which will block on read, so only read |
|
2080 |
* the expected number of bytes, probably 0 |
|
2081 |
*/ |
|
2082 |
int cl = 0, n=0; |
|
2083 |
try { |
|
2084 |
cl = Integer.parseInt (responses.findValue ("Content-Length")); |
|
2085 |
} catch (Exception e) {} |
|
2086 |
for (int i=0; i<cl; ) { |
|
2087 |
if ((n = is.read (cdata)) == -1) { |
|
2088 |
break; |
|
2089 |
} else { |
|
2090 |
i+= n; |
|
2091 |
} |
|
2092 |
} |
|
2093 |
} |
|
2094 |
} catch (IOException e) { |
|
2095 |
http.reuse = false; |
|
2096 |
reuseClient = null; |
|
2097 |
disconnectInternal(); |
|
2098 |
return; |
|
2099 |
} |
|
2100 |
try { |
|
2101 |
if (is instanceof MeteredStream) { |
|
2102 |
is.close(); |
|
2103 |
} |
|
2104 |
} catch (IOException e) { } |
|
2105 |
} |
|
2106 |
responseCode = -1; |
|
2107 |
responses = new MessageHeader(); |
|
2108 |
connected = false; |
|
2109 |
} |
|
2110 |
||
2111 |
/** |
|
2112 |
* Disconnect from the server (for internal use) |
|
2113 |
*/ |
|
2114 |
private void disconnectInternal() { |
|
2115 |
responseCode = -1; |
|
78
65353d0d0e31
6660405: HttpURLConnection returns the wrong InputStream
jccollet
parents:
74
diff
changeset
|
2116 |
inputStream = null; |
2 | 2117 |
if (pi != null) { |
2118 |
pi.finishTracking(); |
|
2119 |
pi = null; |
|
2120 |
} |
|
2121 |
if (http != null) { |
|
2122 |
http.closeServer(); |
|
2123 |
http = null; |
|
2124 |
connected = false; |
|
2125 |
} |
|
2126 |
} |
|
2127 |
||
2128 |
/** |
|
2129 |
* Disconnect from the server (public API) |
|
2130 |
*/ |
|
2131 |
public void disconnect() { |
|
2132 |
||
2133 |
responseCode = -1; |
|
2134 |
if (pi != null) { |
|
2135 |
pi.finishTracking(); |
|
2136 |
pi = null; |
|
2137 |
} |
|
2138 |
||
2139 |
if (http != null) { |
|
2140 |
/* |
|
2141 |
* If we have an input stream this means we received a response |
|
2142 |
* from the server. That stream may have been read to EOF and |
|
2143 |
* dependening on the stream type may already be closed or the |
|
2144 |
* the http client may be returned to the keep-alive cache. |
|
2145 |
* If the http client has been returned to the keep-alive cache |
|
2146 |
* it may be closed (idle timeout) or may be allocated to |
|
2147 |
* another request. |
|
2148 |
* |
|
2149 |
* In other to avoid timing issues we close the input stream |
|
2150 |
* which will either close the underlying connection or return |
|
2151 |
* the client to the cache. If there's a possibility that the |
|
2152 |
* client has been returned to the cache (ie: stream is a keep |
|
2153 |
* alive stream or a chunked input stream) then we remove an |
|
2154 |
* idle connection to the server. Note that this approach |
|
2155 |
* can be considered an approximation in that we may close a |
|
2156 |
* different idle connection to that used by the request. |
|
2157 |
* Additionally it's possible that we close two connections |
|
2158 |
* - the first becuase it wasn't an EOF (and couldn't be |
|
2159 |
* hurried) - the second, another idle connection to the |
|
2160 |
* same server. The is okay because "disconnect" is an |
|
2161 |
* indication that the application doesn't intend to access |
|
2162 |
* this http server for a while. |
|
2163 |
*/ |
|
2164 |
||
2165 |
if (inputStream != null) { |
|
2166 |
HttpClient hc = http; |
|
2167 |
||
2168 |
// un-synchronized |
|
2169 |
boolean ka = hc.isKeepingAlive(); |
|
2170 |
||
2171 |
try { |
|
2172 |
inputStream.close(); |
|
2173 |
} catch (IOException ioe) { } |
|
2174 |
||
2175 |
// if the connection is persistent it may have been closed |
|
2176 |
// or returned to the keep-alive cache. If it's been returned |
|
2177 |
// to the keep-alive cache then we would like to close it |
|
2178 |
// but it may have been allocated |
|
2179 |
||
2180 |
if (ka) { |
|
2181 |
hc.closeIdleConnection(); |
|
2182 |
} |
|
2183 |
||
2184 |
||
2185 |
} else { |
|
2186 |
// We are deliberatly being disconnected so HttpClient |
|
2187 |
// should not try to resend the request no matter what stage |
|
2188 |
// of the connection we are in. |
|
2189 |
http.setDoNotRetry(true); |
|
2190 |
||
2191 |
http.closeServer(); |
|
2192 |
} |
|
2193 |
||
2194 |
// poster = null; |
|
2195 |
http = null; |
|
2196 |
connected = false; |
|
2197 |
} |
|
2198 |
cachedInputStream = null; |
|
2199 |
if (cachedHeaders != null) { |
|
2200 |
cachedHeaders.reset(); |
|
2201 |
} |
|
2202 |
} |
|
2203 |
||
2204 |
public boolean usingProxy() { |
|
2205 |
if (http != null) { |
|
2206 |
return (http.getProxyHostUsed() != null); |
|
2207 |
} |
|
2208 |
return false; |
|
2209 |
} |
|
2210 |
||
2211 |
/** |
|
2212 |
* Gets a header field by name. Returns null if not known. |
|
2213 |
* @param name the name of the header field |
|
2214 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2215 |
@Override |
2 | 2216 |
public String getHeaderField(String name) { |
2217 |
try { |
|
2218 |
getInputStream(); |
|
2219 |
} catch (IOException e) {} |
|
2220 |
||
2221 |
if (cachedHeaders != null) { |
|
2222 |
return cachedHeaders.findValue(name); |
|
2223 |
} |
|
2224 |
||
2225 |
return responses.findValue(name); |
|
2226 |
} |
|
2227 |
||
2228 |
/** |
|
2229 |
* Returns an unmodifiable Map of the header fields. |
|
2230 |
* The Map keys are Strings that represent the |
|
2231 |
* response-header field names. Each Map value is an |
|
2232 |
* unmodifiable List of Strings that represents |
|
2233 |
* the corresponding field values. |
|
2234 |
* |
|
2235 |
* @return a Map of header fields |
|
2236 |
* @since 1.4 |
|
2237 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2238 |
@Override |
51 | 2239 |
public Map<String, List<String>> getHeaderFields() { |
2 | 2240 |
try { |
2241 |
getInputStream(); |
|
2242 |
} catch (IOException e) {} |
|
2243 |
||
2244 |
if (cachedHeaders != null) { |
|
2245 |
return cachedHeaders.getHeaders(); |
|
2246 |
} |
|
2247 |
||
2248 |
return responses.getHeaders(); |
|
2249 |
} |
|
2250 |
||
2251 |
/** |
|
2252 |
* Gets a header field by index. Returns null if not known. |
|
2253 |
* @param n the index of the header field |
|
2254 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2255 |
@Override |
2 | 2256 |
public String getHeaderField(int n) { |
2257 |
try { |
|
2258 |
getInputStream(); |
|
2259 |
} catch (IOException e) {} |
|
2260 |
||
2261 |
if (cachedHeaders != null) { |
|
2262 |
return cachedHeaders.getValue(n); |
|
2263 |
} |
|
2264 |
return responses.getValue(n); |
|
2265 |
} |
|
2266 |
||
2267 |
/** |
|
2268 |
* Gets a header field by index. Returns null if not known. |
|
2269 |
* @param n the index of the header field |
|
2270 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2271 |
@Override |
2 | 2272 |
public String getHeaderFieldKey(int n) { |
2273 |
try { |
|
2274 |
getInputStream(); |
|
2275 |
} catch (IOException e) {} |
|
2276 |
||
2277 |
if (cachedHeaders != null) { |
|
2278 |
return cachedHeaders.getKey(n); |
|
2279 |
} |
|
2280 |
||
2281 |
return responses.getKey(n); |
|
2282 |
} |
|
2283 |
||
2284 |
/** |
|
2285 |
* Sets request property. If a property with the key already |
|
2286 |
* exists, overwrite its value with the new value. |
|
2287 |
* @param value the value to be set |
|
2288 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2289 |
@Override |
2 | 2290 |
public void setRequestProperty(String key, String value) { |
2291 |
if (connected) |
|
2292 |
throw new IllegalStateException("Already connected"); |
|
2293 |
if (key == null) |
|
2294 |
throw new NullPointerException ("key is null"); |
|
2295 |
||
2296 |
checkMessageHeader(key, value); |
|
2297 |
requests.set(key, value); |
|
2298 |
} |
|
2299 |
||
2300 |
/** |
|
2301 |
* Adds a general request property specified by a |
|
2302 |
* key-value pair. This method will not overwrite |
|
2303 |
* existing values associated with the same key. |
|
2304 |
* |
|
2305 |
* @param key the keyword by which the request is known |
|
2306 |
* (e.g., "<code>accept</code>"). |
|
2307 |
* @param value the value associated with it. |
|
2308 |
* @see #getRequestProperties(java.lang.String) |
|
2309 |
* @since 1.4 |
|
2310 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2311 |
@Override |
2 | 2312 |
public void addRequestProperty(String key, String value) { |
2313 |
if (connected) |
|
2314 |
throw new IllegalStateException("Already connected"); |
|
2315 |
if (key == null) |
|
2316 |
throw new NullPointerException ("key is null"); |
|
2317 |
||
2318 |
checkMessageHeader(key, value); |
|
2319 |
requests.add(key, value); |
|
2320 |
} |
|
2321 |
||
2322 |
// |
|
2323 |
// Set a property for authentication. This can safely disregard |
|
2324 |
// the connected test. |
|
2325 |
// |
|
2326 |
void setAuthenticationProperty(String key, String value) { |
|
2327 |
checkMessageHeader(key, value); |
|
2328 |
requests.set(key, value); |
|
2329 |
} |
|
2330 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2331 |
@Override |
2 | 2332 |
public String getRequestProperty (String key) { |
2333 |
// don't return headers containing security sensitive information |
|
2334 |
if (key != null) { |
|
2335 |
for (int i=0; i < EXCLUDE_HEADERS.length; i++) { |
|
2336 |
if (key.equalsIgnoreCase(EXCLUDE_HEADERS[i])) { |
|
2337 |
return null; |
|
2338 |
} |
|
2339 |
} |
|
2340 |
} |
|
2341 |
return requests.findValue(key); |
|
2342 |
} |
|
2343 |
||
2344 |
/** |
|
2345 |
* Returns an unmodifiable Map of general request |
|
2346 |
* properties for this connection. The Map keys |
|
2347 |
* are Strings that represent the request-header |
|
2348 |
* field names. Each Map value is a unmodifiable List |
|
2349 |
* of Strings that represents the corresponding |
|
2350 |
* field values. |
|
2351 |
* |
|
2352 |
* @return a Map of the general request properties for this connection. |
|
2353 |
* @throws IllegalStateException if already connected |
|
2354 |
* @since 1.4 |
|
2355 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2356 |
@Override |
51 | 2357 |
public Map<String, List<String>> getRequestProperties() { |
2 | 2358 |
if (connected) |
2359 |
throw new IllegalStateException("Already connected"); |
|
2360 |
||
2361 |
// exclude headers containing security-sensitive info |
|
2362 |
return requests.getHeaders(EXCLUDE_HEADERS); |
|
2363 |
} |
|
2364 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2365 |
@Override |
2 | 2366 |
public void setConnectTimeout(int timeout) { |
2367 |
if (timeout < 0) |
|
2368 |
throw new IllegalArgumentException("timeouts can't be negative"); |
|
2369 |
connectTimeout = timeout; |
|
2370 |
} |
|
2371 |
||
2372 |
||
2373 |
/** |
|
2374 |
* Returns setting for connect timeout. |
|
2375 |
* <p> |
|
2376 |
* 0 return implies that the option is disabled |
|
2377 |
* (i.e., timeout of infinity). |
|
2378 |
* |
|
2379 |
* @return an <code>int</code> that indicates the connect timeout |
|
2380 |
* value in milliseconds |
|
2381 |
* @see java.net.URLConnection#setConnectTimeout(int) |
|
2382 |
* @see java.net.URLConnection#connect() |
|
2383 |
* @since 1.5 |
|
2384 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2385 |
@Override |
2 | 2386 |
public int getConnectTimeout() { |
2387 |
return (connectTimeout < 0 ? 0 : connectTimeout); |
|
2388 |
} |
|
2389 |
||
2390 |
/** |
|
2391 |
* Sets the read timeout to a specified timeout, in |
|
2392 |
* milliseconds. A non-zero value specifies the timeout when |
|
2393 |
* reading from Input stream when a connection is established to a |
|
2394 |
* resource. If the timeout expires before there is data available |
|
2395 |
* for read, a java.net.SocketTimeoutException is raised. A |
|
2396 |
* timeout of zero is interpreted as an infinite timeout. |
|
2397 |
* |
|
2398 |
* <p> Some non-standard implementation of this method ignores the |
|
2399 |
* specified timeout. To see the read timeout set, please call |
|
2400 |
* getReadTimeout(). |
|
2401 |
* |
|
2402 |
* @param timeout an <code>int</code> that specifies the timeout |
|
2403 |
* value to be used in milliseconds |
|
2404 |
* @throws IllegalArgumentException if the timeout parameter is negative |
|
2405 |
* |
|
2406 |
* @see java.net.URLConnectiongetReadTimeout() |
|
2407 |
* @see java.io.InputStream#read() |
|
2408 |
* @since 1.5 |
|
2409 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2410 |
@Override |
2 | 2411 |
public void setReadTimeout(int timeout) { |
2412 |
if (timeout < 0) |
|
2413 |
throw new IllegalArgumentException("timeouts can't be negative"); |
|
2414 |
readTimeout = timeout; |
|
2415 |
} |
|
2416 |
||
2417 |
/** |
|
2418 |
* Returns setting for read timeout. 0 return implies that the |
|
2419 |
* option is disabled (i.e., timeout of infinity). |
|
2420 |
* |
|
2421 |
* @return an <code>int</code> that indicates the read timeout |
|
2422 |
* value in milliseconds |
|
2423 |
* |
|
2424 |
* @see java.net.URLConnection#setReadTimeout(int) |
|
2425 |
* @see java.io.InputStream#read() |
|
2426 |
* @since 1.5 |
|
2427 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2428 |
@Override |
2 | 2429 |
public int getReadTimeout() { |
2430 |
return readTimeout < 0 ? 0 : readTimeout; |
|
2431 |
} |
|
2432 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2433 |
@Override |
2 | 2434 |
protected void finalize() { |
2435 |
// this should do nothing. The stream finalizer will close |
|
2436 |
// the fd |
|
2437 |
} |
|
2438 |
||
2439 |
String getMethod() { |
|
2440 |
return method; |
|
2441 |
} |
|
2442 |
||
51 | 2443 |
private MessageHeader mapToMessageHeader(Map<String, List<String>> map) { |
2 | 2444 |
MessageHeader headers = new MessageHeader(); |
2445 |
if (map == null || map.isEmpty()) { |
|
2446 |
return headers; |
|
2447 |
} |
|
51 | 2448 |
for (Map.Entry<String, List<String>> entry : map.entrySet()) { |
2449 |
String key = entry.getKey(); |
|
2450 |
List<String> values = entry.getValue(); |
|
2451 |
for (String value : values) { |
|
2 | 2452 |
if (key == null) { |
2453 |
headers.prepend(key, value); |
|
2454 |
} else { |
|
2455 |
headers.add(key, value); |
|
2456 |
} |
|
2457 |
} |
|
2458 |
} |
|
2459 |
return headers; |
|
2460 |
} |
|
2461 |
||
2462 |
/* The purpose of this wrapper is just to capture the close() call |
|
2463 |
* so we can check authentication information that may have |
|
2464 |
* arrived in a Trailer field |
|
2465 |
*/ |
|
2466 |
class HttpInputStream extends FilterInputStream { |
|
2467 |
private CacheRequest cacheRequest; |
|
2468 |
private OutputStream outputStream; |
|
2469 |
private boolean marked = false; |
|
2470 |
private int inCache = 0; |
|
2471 |
private int markCount = 0; |
|
2472 |
||
2473 |
public HttpInputStream (InputStream is) { |
|
2474 |
super (is); |
|
2475 |
this.cacheRequest = null; |
|
2476 |
this.outputStream = null; |
|
2477 |
} |
|
2478 |
||
2479 |
public HttpInputStream (InputStream is, CacheRequest cacheRequest) { |
|
2480 |
super (is); |
|
2481 |
this.cacheRequest = cacheRequest; |
|
2482 |
try { |
|
2483 |
this.outputStream = cacheRequest.getBody(); |
|
2484 |
} catch (IOException ioex) { |
|
2485 |
this.cacheRequest.abort(); |
|
2486 |
this.cacheRequest = null; |
|
2487 |
this.outputStream = null; |
|
2488 |
} |
|
2489 |
} |
|
2490 |
||
2491 |
/** |
|
2492 |
* Marks the current position in this input stream. A subsequent |
|
2493 |
* call to the <code>reset</code> method repositions this stream at |
|
2494 |
* the last marked position so that subsequent reads re-read the same |
|
2495 |
* bytes. |
|
2496 |
* <p> |
|
2497 |
* The <code>readlimit</code> argument tells this input stream to |
|
2498 |
* allow that many bytes to be read before the mark position gets |
|
2499 |
* invalidated. |
|
2500 |
* <p> |
|
2501 |
* This method simply performs <code>in.mark(readlimit)</code>. |
|
2502 |
* |
|
2503 |
* @param readlimit the maximum limit of bytes that can be read before |
|
2504 |
* the mark position becomes invalid. |
|
2505 |
* @see java.io.FilterInputStream#in |
|
2506 |
* @see java.io.FilterInputStream#reset() |
|
2507 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2508 |
@Override |
2 | 2509 |
public synchronized void mark(int readlimit) { |
2510 |
super.mark(readlimit); |
|
2511 |
if (cacheRequest != null) { |
|
2512 |
marked = true; |
|
2513 |
markCount = 0; |
|
2514 |
} |
|
2515 |
} |
|
2516 |
||
2517 |
/** |
|
2518 |
* Repositions this stream to the position at the time the |
|
2519 |
* <code>mark</code> method was last called on this input stream. |
|
2520 |
* <p> |
|
2521 |
* This method |
|
2522 |
* simply performs <code>in.reset()</code>. |
|
2523 |
* <p> |
|
2524 |
* Stream marks are intended to be used in |
|
2525 |
* situations where you need to read ahead a little to see what's in |
|
2526 |
* the stream. Often this is most easily done by invoking some |
|
2527 |
* general parser. If the stream is of the type handled by the |
|
2528 |
* parse, it just chugs along happily. If the stream is not of |
|
2529 |
* that type, the parser should toss an exception when it fails. |
|
2530 |
* If this happens within readlimit bytes, it allows the outer |
|
2531 |
* code to reset the stream and try another parser. |
|
2532 |
* |
|
2533 |
* @exception IOException if the stream has not been marked or if the |
|
2534 |
* mark has been invalidated. |
|
2535 |
* @see java.io.FilterInputStream#in |
|
2536 |
* @see java.io.FilterInputStream#mark(int) |
|
2537 |
*/ |
|
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2538 |
@Override |
2 | 2539 |
public synchronized void reset() throws IOException { |
2540 |
super.reset(); |
|
2541 |
if (cacheRequest != null) { |
|
2542 |
marked = false; |
|
2543 |
inCache += markCount; |
|
2544 |
} |
|
2545 |
} |
|
2546 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2547 |
@Override |
2 | 2548 |
public int read() throws IOException { |
2549 |
try { |
|
2550 |
byte[] b = new byte[1]; |
|
2551 |
int ret = read(b); |
|
2552 |
return (ret == -1? ret : (b[0] & 0x00FF)); |
|
2553 |
} catch (IOException ioex) { |
|
2554 |
if (cacheRequest != null) { |
|
2555 |
cacheRequest.abort(); |
|
2556 |
} |
|
2557 |
throw ioex; |
|
2558 |
} |
|
2559 |
} |
|
2560 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2561 |
@Override |
2 | 2562 |
public int read(byte[] b) throws IOException { |
2563 |
return read(b, 0, b.length); |
|
2564 |
} |
|
2565 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2566 |
@Override |
2 | 2567 |
public int read(byte[] b, int off, int len) throws IOException { |
2568 |
try { |
|
2569 |
int newLen = super.read(b, off, len); |
|
2570 |
int nWrite; |
|
2571 |
// write to cache |
|
2572 |
if (inCache > 0) { |
|
2573 |
if (inCache >= newLen) { |
|
2574 |
inCache -= newLen; |
|
2575 |
nWrite = 0; |
|
2576 |
} else { |
|
2577 |
nWrite = newLen - inCache; |
|
2578 |
inCache = 0; |
|
2579 |
} |
|
2580 |
} else { |
|
2581 |
nWrite = newLen; |
|
2582 |
} |
|
2583 |
if (nWrite > 0 && outputStream != null) |
|
2584 |
outputStream.write(b, off + (newLen-nWrite), nWrite); |
|
2585 |
if (marked) { |
|
2586 |
markCount += newLen; |
|
2587 |
} |
|
2588 |
return newLen; |
|
2589 |
} catch (IOException ioex) { |
|
2590 |
if (cacheRequest != null) { |
|
2591 |
cacheRequest.abort(); |
|
2592 |
} |
|
2593 |
throw ioex; |
|
2594 |
} |
|
2595 |
} |
|
2596 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2597 |
@Override |
2 | 2598 |
public void close () throws IOException { |
2599 |
try { |
|
2600 |
if (outputStream != null) { |
|
2601 |
if (read() != -1) { |
|
2602 |
cacheRequest.abort(); |
|
2603 |
} else { |
|
2604 |
outputStream.close(); |
|
2605 |
} |
|
2606 |
} |
|
2607 |
super.close (); |
|
2608 |
} catch (IOException ioex) { |
|
2609 |
if (cacheRequest != null) { |
|
2610 |
cacheRequest.abort(); |
|
2611 |
} |
|
2612 |
throw ioex; |
|
2613 |
} finally { |
|
2614 |
HttpURLConnection.this.http = null; |
|
2615 |
checkResponseCredentials (true); |
|
2616 |
} |
|
2617 |
} |
|
2618 |
} |
|
2619 |
||
2620 |
class StreamingOutputStream extends FilterOutputStream { |
|
2621 |
||
2622 |
int expected; |
|
2623 |
int written; |
|
2624 |
boolean closed; |
|
2625 |
boolean error; |
|
2626 |
IOException errorExcp; |
|
2627 |
||
2628 |
/** |
|
2629 |
* expectedLength == -1 if the stream is chunked |
|
2630 |
* expectedLength > 0 if the stream is fixed content-length |
|
2631 |
* In the 2nd case, we make sure the expected number of |
|
2632 |
* of bytes are actually written |
|
2633 |
*/ |
|
2634 |
StreamingOutputStream (OutputStream os, int expectedLength) { |
|
2635 |
super (os); |
|
2636 |
expected = expectedLength; |
|
2637 |
written = 0; |
|
2638 |
closed = false; |
|
2639 |
error = false; |
|
2640 |
} |
|
2641 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2642 |
@Override |
2 | 2643 |
public void write (int b) throws IOException { |
2644 |
checkError(); |
|
2645 |
written ++; |
|
2646 |
if (expected != -1 && written > expected) { |
|
2647 |
throw new IOException ("too many bytes written"); |
|
2648 |
} |
|
2649 |
out.write (b); |
|
2650 |
} |
|
2651 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2652 |
@Override |
2 | 2653 |
public void write (byte[] b) throws IOException { |
2654 |
write (b, 0, b.length); |
|
2655 |
} |
|
2656 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2657 |
@Override |
2 | 2658 |
public void write (byte[] b, int off, int len) throws IOException { |
2659 |
checkError(); |
|
2660 |
written += len; |
|
2661 |
if (expected != -1 && written > expected) { |
|
2662 |
out.close (); |
|
2663 |
throw new IOException ("too many bytes written"); |
|
2664 |
} |
|
2665 |
out.write (b, off, len); |
|
2666 |
} |
|
2667 |
||
2668 |
void checkError () throws IOException { |
|
2669 |
if (closed) { |
|
2670 |
throw new IOException ("Stream is closed"); |
|
2671 |
} |
|
2672 |
if (error) { |
|
2673 |
throw errorExcp; |
|
2674 |
} |
|
2675 |
if (((PrintStream)out).checkError()) { |
|
2676 |
throw new IOException("Error writing request body to server"); |
|
2677 |
} |
|
2678 |
} |
|
2679 |
||
2680 |
/* this is called to check that all the bytes |
|
2681 |
* that were supposed to be written were written |
|
2682 |
* and that the stream is now closed(). |
|
2683 |
*/ |
|
2684 |
boolean writtenOK () { |
|
2685 |
return closed && ! error; |
|
2686 |
} |
|
2687 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2688 |
@Override |
2 | 2689 |
public void close () throws IOException { |
2690 |
if (closed) { |
|
2691 |
return; |
|
2692 |
} |
|
2693 |
closed = true; |
|
2694 |
if (expected != -1) { |
|
2695 |
/* not chunked */ |
|
2696 |
if (written != expected) { |
|
2697 |
error = true; |
|
2698 |
errorExcp = new IOException ("insufficient data written"); |
|
2699 |
out.close (); |
|
2700 |
throw errorExcp; |
|
2701 |
} |
|
2702 |
super.flush(); /* can't close the socket */ |
|
2703 |
} else { |
|
2704 |
/* chunked */ |
|
2705 |
super.close (); /* force final chunk to be written */ |
|
2706 |
/* trailing \r\n */ |
|
2707 |
OutputStream o = http.getOutputStream(); |
|
2708 |
o.write ('\r'); |
|
2709 |
o.write ('\n'); |
|
2710 |
o.flush(); |
|
2711 |
} |
|
2712 |
} |
|
2713 |
} |
|
2714 |
||
2715 |
||
2716 |
static class ErrorStream extends InputStream { |
|
2717 |
ByteBuffer buffer; |
|
2718 |
InputStream is; |
|
2719 |
||
2720 |
private ErrorStream(ByteBuffer buf) { |
|
2721 |
buffer = buf; |
|
2722 |
is = null; |
|
2723 |
} |
|
2724 |
||
2725 |
private ErrorStream(ByteBuffer buf, InputStream is) { |
|
2726 |
buffer = buf; |
|
2727 |
this.is = is; |
|
2728 |
} |
|
2729 |
||
2730 |
// when this method is called, it's either the case that cl > 0, or |
|
2731 |
// if chunk-encoded, cl = -1; in other words, cl can't be 0 |
|
2732 |
public static InputStream getErrorStream(InputStream is, long cl, HttpClient http) { |
|
2733 |
||
2734 |
// cl can't be 0; this following is here for extra precaution |
|
2735 |
if (cl == 0) { |
|
2736 |
return null; |
|
2737 |
} |
|
2738 |
||
2739 |
try { |
|
2740 |
// set SO_TIMEOUT to 1/5th of the total timeout |
|
2741 |
// remember the old timeout value so that we can restore it |
|
2742 |
int oldTimeout = http.setTimeout(timeout4ESBuffer/5); |
|
2743 |
||
2744 |
long expected = 0; |
|
2745 |
boolean isChunked = false; |
|
2746 |
// the chunked case |
|
2747 |
if (cl < 0) { |
|
2748 |
expected = bufSize4ES; |
|
2749 |
isChunked = true; |
|
2750 |
} else { |
|
2751 |
expected = cl; |
|
2752 |
} |
|
2753 |
if (expected <= bufSize4ES) { |
|
2754 |
int exp = (int) expected; |
|
2755 |
byte[] buffer = new byte[exp]; |
|
2756 |
int count = 0, time = 0, len = 0; |
|
2757 |
do { |
|
2758 |
try { |
|
2759 |
len = is.read(buffer, count, |
|
2760 |
buffer.length - count); |
|
2761 |
if (len < 0) { |
|
2762 |
if (isChunked) { |
|
2763 |
// chunked ended |
|
2764 |
// if chunked ended prematurely, |
|
2765 |
// an IOException would be thrown |
|
2766 |
break; |
|
2767 |
} |
|
2768 |
// the server sends less than cl bytes of data |
|
2769 |
throw new IOException("the server closes"+ |
|
2770 |
" before sending "+cl+ |
|
2771 |
" bytes of data"); |
|
2772 |
} |
|
2773 |
count += len; |
|
2774 |
} catch (SocketTimeoutException ex) { |
|
2775 |
time += timeout4ESBuffer/5; |
|
2776 |
} |
|
2777 |
} while (count < exp && time < timeout4ESBuffer); |
|
2778 |
||
2779 |
// reset SO_TIMEOUT to old value |
|
2780 |
http.setTimeout(oldTimeout); |
|
2781 |
||
2782 |
// if count < cl at this point, we will not try to reuse |
|
2783 |
// the connection |
|
2784 |
if (count == 0) { |
|
2785 |
// since we haven't read anything, |
|
2786 |
// we will return the underlying |
|
2787 |
// inputstream back to the application |
|
2788 |
return null; |
|
2789 |
} else if ((count == expected && !(isChunked)) || (isChunked && len <0)) { |
|
2790 |
// put the connection into keep-alive cache |
|
2791 |
// the inputstream will try to do the right thing |
|
2792 |
is.close(); |
|
2793 |
return new ErrorStream(ByteBuffer.wrap(buffer, 0, count)); |
|
2794 |
} else { |
|
2795 |
// we read part of the response body |
|
2796 |
return new ErrorStream( |
|
2797 |
ByteBuffer.wrap(buffer, 0, count), is); |
|
2798 |
} |
|
2799 |
} |
|
2800 |
return null; |
|
2801 |
} catch (IOException ioex) { |
|
2802 |
// ioex.printStackTrace(); |
|
2803 |
return null; |
|
2804 |
} |
|
2805 |
} |
|
2806 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2807 |
@Override |
2 | 2808 |
public int available() throws IOException { |
2809 |
if (is == null) { |
|
2810 |
return buffer.remaining(); |
|
2811 |
} else { |
|
2812 |
return buffer.remaining()+is.available(); |
|
2813 |
} |
|
2814 |
} |
|
2815 |
||
2816 |
public int read() throws IOException { |
|
2817 |
byte[] b = new byte[1]; |
|
2818 |
int ret = read(b); |
|
2819 |
return (ret == -1? ret : (b[0] & 0x00FF)); |
|
2820 |
} |
|
2821 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2822 |
@Override |
2 | 2823 |
public int read(byte[] b) throws IOException { |
2824 |
return read(b, 0, b.length); |
|
2825 |
} |
|
2826 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2827 |
@Override |
2 | 2828 |
public int read(byte[] b, int off, int len) throws IOException { |
2829 |
int rem = buffer.remaining(); |
|
2830 |
if (rem > 0) { |
|
2831 |
int ret = rem < len? rem : len; |
|
2832 |
buffer.get(b, off, ret); |
|
2833 |
return ret; |
|
2834 |
} else { |
|
2835 |
if (is == null) { |
|
2836 |
return -1; |
|
2837 |
} else { |
|
2838 |
return is.read(b, off, len); |
|
2839 |
} |
|
2840 |
} |
|
2841 |
} |
|
2842 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2843 |
@Override |
2 | 2844 |
public void close() throws IOException { |
2845 |
buffer = null; |
|
2846 |
if (is != null) { |
|
2847 |
is.close(); |
|
2848 |
} |
|
2849 |
} |
|
2850 |
} |
|
2851 |
} |
|
2852 |
||
2853 |
/** An input stream that just returns EOF. This is for |
|
2854 |
* HTTP URLConnections that are KeepAlive && use the |
|
2855 |
* HEAD method - i.e., stream not dead, but nothing to be read. |
|
2856 |
*/ |
|
2857 |
||
2858 |
class EmptyInputStream extends InputStream { |
|
2859 |
||
74
068494063b1b
6641309: Wrong Cookie separator used in HttpURLConnection
jccollet
parents:
2
diff
changeset
|
2860 |
@Override |
2 | 2861 |
public int available() { |
2862 |
return 0; |
|
2863 |
} |
|
2864 |
||
2865 |
public int read() { |
|
2866 |
return -1; |
|
2867 |
} |
|
2868 |
} |