5839N/A * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A class to represent an HTTP connection to a remote object. 0N/A /* max # of allowed re-directs */ 0N/A /* Not all servers support the (Proxy)-Authentication-Info headers. 0N/A * By default, we don't require them to be sent 0N/A "cannot retry due to proxy authentication, in streaming mode";
0N/A "cannot retry due to server authentication, in streaming mode";
0N/A "cannot retry due to redirection, in streaming mode";
0N/A * System properties related to error stream handling: 0N/A * sun.net.http.errorstream.enableBuffering = <boolean> 0N/A * With the above system property set to true (default is false), 0N/A * when the response code is >=400, the HTTP handler will try to 0N/A * buffer the response body (up to a certain amount and within a 0N/A * time limit). Thus freeing up the underlying socket connection 0N/A * for reuse. The rationale behind this is that usually when the 0N/A * server responds with a >=400 error (client error or server 0N/A * error, such as 404 file not found), the server will send a 0N/A * small response body to explain who to contact and what to do to 0N/A * recover. With this property set to true, even if the 0N/A * application doesn't call getErrorStream(), read the response 0N/A * body, and then call close(), the underlying socket connection 0N/A * can still be kept-alive and reused. The following two system 0N/A * properties provide further control to the error stream 0N/A * buffering behaviour. 0N/A * sun.net.http.errorstream.timeout = <int> 0N/A * the timeout (in millisec) waiting the error stream 0N/A * to be buffered; default is 300 ms 0N/A * sun.net.http.errorstream.bufferSize = <int> 0N/A * the size (in bytes) to use for the buffering the error stream; 0N/A /* Should we enable buffering of error streams? */ 0N/A /* timeout waiting for read for buffered error stream; 0N/A /* buffer size for buffered error stream; 2910N/A * Restrict setting of request headers through the public api 2910N/A * consistent with JavaScript XMLHttpRequest2 with a few 2910N/A * exceptions. Disallowed headers are silently ignored for 2910N/A * backwards compatibility reasons rather than throwing a 2910N/A * SecurityException. For example, some applets set the 2910N/A * Host header since old JREs did not implement HTTP 1.1. 2910N/A * Additionally, any header starting with Sec- is 2910N/A * The following headers are allowed for historical reasons: 2910N/A * Accept-Charset, Accept-Encoding, Cookie, Cookie2, Date, 2910N/A * Referer, TE, User-Agent, headers beginning with Proxy-. 2910N/A * The following headers are allowed in a limited form: 2910N/A /* Restricted by XMLHttpRequest2 */ 2910N/A "Access-Control-Request-Headers",
2910N/A "Access-Control-Request-Method",
2910N/A "Connection",
/* close is allowed */ 2910N/A "Content-Transfer-Encoding",
0N/A "sun.net.http.errorstream.bufferSize",
4096)).
intValue();
0N/A // the following http request headers should NOT have their values 0N/A // returned for security reasons. 0N/A "Proxy-Authorization",
2910N/A // also exclude system cookies when any might be set 0N/A // the cached response, and cached response headers and body 0N/A /* output stream to server */ 0N/A /* buffered error stream */ 0N/A /* User set Cookies */ 0N/A /* We only have a single static authenticator for now. 0N/A * REMIND: backwards compatibility with JDK 1.1. Should be 0N/A * eliminated for JDK 2.0. 0N/A /* all the headers we send 0N/A * NOTE: do *NOT* dump out the content of 'requests' in the 0N/A * output or stacktrace since it may contain security-sensitive 0N/A * headers such as those defined in EXCLUDE_HEADERS. 0N/A /* The following two fields are only used with Digest Authentication */ 0N/A /* Current credentials in use */ 0N/A private boolean doingNTLM2ndStage =
false;
/* doing the 2nd stage of an NTLM server authentication */ 1670N/A /* try auth without calling Authenticator. Used for transparent NTLM authentication */ 1315N/A /* Used by Windows specific code */ 0N/A /* Set if the user is manually setting the Authorization or Proxy-Authorization headers */ 0N/A /* Progress source */ 0N/A /* all the response headers we get back */ 0N/A /* the stream _from_ the server */ 0N/A /* post stream _to_ the server, if any */ 0N/A /* Indicates if the std. request headers have been set in requests. */ 0N/A /* Indicates whether a request has already failed or not */ 0N/A /* Remembered Exception, we will throw it again if somebody 0N/A calls getInputStream after disconnect */ 0N/A /* If we decide we want to reuse a client, we put it here */ 256N/A /* Setting up a tunnel */ 256N/A /* Tunnel has been successfully setup */ 2981N/A /* Redefine timeouts from java.net.URLConnection as we need -1 to mean 0N/A * not set. This is to ensure backward compatibility. 0N/A * privileged request password authentication 2910N/A * Exceptions to restricted headers: 2910N/A * Allow "Connection: close". 2910N/A * Checks the validity of http message header and whether the header 2910N/A * is restricted and throws IllegalArgumentException if invalid or 1791N/A /* Used for Windows NTLM implementation */ 0N/A * checks the validity of http message header and throws 0N/A * IllegalArgumentException if invalid. 0N/A "Illegal character(s) in message header field: " +
key);
0N/A if ((c==
' ') || (c==
'\t')) {
0N/A // ok, check the next occurrence 0N/A "Illegal character(s) in message header value: " +
value);
0N/A /* adds the standard key/val pairs to reqests if necessary & write to 0N/A /* print all message headers in the MessageHeader 0N/A * onto the wire - all the ones we've set and any 0N/A * others that have been set 0N/A // send any pre-emptive authentication 0N/A /* We're very particular about the order in which we 0N/A * set the request headers here. The order should not 0N/A * matter, but some careless CGI programs have been 0N/A * written to expect a very particular order of the 0N/A * standard headers. To name names, the order in which 0N/A * Navigator3.0 sends them. In particular, we make *sure* 0N/A * to send Content-type: <> and Content-length:<> second 0N/A * to last and last, respectively, in the case of a POST 0N/A * For HTTP/1.1 the default behavior is to keep connections alive. 0N/A * However, we may be talking to a 1.0 server so we should set 0N/A * keep-alive just in case, except if we have encountered an error 0N/A * or if keep alive is disabled via a system property 0N/A // Try keep-alive only on first attempt 0N/A * RFC 2616 HTTP/1.1 section 14.10 says: 0N/A * HTTP/1.1 applications that do not support persistent 0N/A * connections MUST include the "close" connection option 0N/A // Set modified since if necessary 0N/A //use the preferred date format according to RFC 2068(HTTP1.1), 0N/A // RFC 822 and RFC 1123 0N/A // check for preemptive authorization 0N/A // Sets "Authorization" 705N/A }
else {
/* fixed content length */ 0N/A /* close it, so no more data can be added */ 2907N/A "use streaming mode for chunked encoding");
0N/A // get applicable cookies based on the uri and request headers 0N/A // add them to the existing request headers 0N/A }
else {
// try once more 0N/A * Create a new HttpClient object, bypassing the cache of 0N/A * @param url the URL being accessed 0N/A * Obtain a HttpsClient object. Use the cached copy if specified. 0N/A * @param url the URL being accessed 0N/A * @param useCache whether the cached connection should be used 0N/A * Create a new HttpClient object, set up so that it uses 0N/A * per-instance proxying to the given HTTP proxy. This 0N/A * @param url the URL being accessed 0N/A * @param proxyHost the proxy host to use 0N/A * @param proxyPort the proxy port to use 0N/A * Obtain a HttpClient object, set up so that it uses per-instance 0N/A * proxying to the given HTTP proxy. Use the cached copy of HTTP 0N/A * @param url the URL being accessed 0N/A * @param proxyHost the proxy host to use 0N/A * @param proxyPort the proxy port to use 0N/A * @param useCache whether the cached connection should be used 0N/A // we set proxy == null to distinguish this case with the case 0N/A // when per connection proxy is set 0N/A /** this constructor is used by other protocol handlers such as ftp 0N/A that want to use http to fetch urls on their behalf.*/ 1503N/A /* Application set Proxies should not have access to cookies 1503N/A * in a secure environment unless explicitly allowed. */ 0N/A * @deprecated. Use java.net.Authenticator.setDefault() instead. 0N/A * opens a stream allowing redirects only to the same host. 0N/A // We want to open the input stream before 0N/A // getting headers, because getHeaderField() 0N/A // et al swallow IOExceptions. 0N/A // Same as java.net.URL.hostsEqual 0N/A // Have to resolve addresses before comparing, otherwise 0N/A // names like tachyon and tachyon.eng would compare different 0N/A // overridden in HTTPS subclass 0N/A // try to see if request can be served from local cache 0N/A // ignore and commence normal connection 0N/A /* Try to open connections using the following scheme, 0N/A * return on the first one that's successful: 0N/A * 1) if (instProxy != null) 0N/A * connect to instProxy; raise exception if failed 0N/A * 2) else use system default ProxySelector 0N/A * 3) is 2) fails, make direct connection 0N/A * Do we have to use a proxy? 0N/A // make sure to construct new connection if first 0N/A // fallback to direct connection 0N/A // No proxy selector, create http client with no proxy 0N/A // make sure to construct new connection if first 0N/A // make sure to construct new connection if first 0N/A // constructor to HTTP client calls openserver 0N/A // subclass HttpsClient will overwrite & return an instance of HttpsClient 0N/A // subclass HttpsClient will overwrite & return an instance of HttpsClient 1252N/A // Expect: 100-Continue was set, so check the return code for 1252N/A // 5s read timeout in case the server doesn't understand 1252N/A // Can't use getResponseCode() yet 1252N/A // Parse the response which is of the form: 1252N/A // HTTP/1.1 417 Expectation Failed 1252N/A // Response code is 2nd token on the line 0N/A * - get output, [write output,] get input, [read input] 0N/A * - get output, [write output] 0N/A * [interpreted as GET] 0N/A * - get input, [read input] 0N/A * - get input, [read input,] get output, [write output] 0N/A +
" if doOutput=false - call setDoOutput(true)");
0N/A " doesn't support output");
0N/A // if there's already an input stream open, throw an exception 705N/A }
else {
/* must be fixed content length */ 1252N/A // Save the response code which may have been set while enforcing 1252N/A // the 100-continue. disconnectInternal() forces it to -1 0N/A * get applicable cookies based on the uri and request headers 0N/A * add them to the existing request headers 0N/A // we only want to capture the user defined Cookies once, as 0N/A // they cannot be changed by user code after we are connected, 0N/A // remove old Cookie header before setting new one. 0N/A // ignore all entries that don't have "Cookie" 0N/A // or "Cookie2" as keys 51N/A // strip off the trailing '; ' 0N/A }
// end of getting cookies 0N/A +
" if doInput=false (call setDoInput(true))");
0N/A /* make sure stream is closed */ 0N/A * In some cases, the Negotiate auth is supported for the 0N/A * remote host but the negotiate process still fails (For 0N/A * example, if the web page is located on a backend server 0N/A * and delegation is needed but fails). The authentication 0N/A * process will start again, and we need to detect this 0N/A * kind of failure and do proper fallback (say, to NTLM). 0N/A * In order to achieve this, the inNegotiate flag is set 0N/A * when the first negotiate challenge is met (and reset 0N/A * if authentication is finished). If a fresh new negotiate 0N/A * challenge (no parameter) is found while inNegotiate is 0N/A * set, we know there's a failed auth attempt recently. 0N/A * Here we'll ignore the header line so that fallback 0N/A * inNegotiateProxy is for proxy authentication. 0N/A // If the user has set either of these headers then do not remove them 0N/A // Check if URL should be metered 0N/A /* REMIND: This exists to fix the HttpsURLConnection subclass. 0N/A * Hotjava needs to run on JDK1.1FCS. Do proper fix once a 0N/A * proper solution for SSL can be found. 0N/A // Read comments labeled "Failed Negotiate" for details. 0N/A // changes: add a 3rd parameter to the constructor of 0N/A // AuthenticationHeader, so that NegotiateAuthentication. 0N/A // isSupported can be tested. 0N/A // The other 2 appearances of "new AuthenticationHeader" is 0N/A // altered in similar ways. 0N/A /* in this case, only one header field will be present */ 0N/A // cache proxy authentication info 0N/A // cache auth info on success, domain header not relevant. 0N/A // Read comments labeled "Failed Negotiate" for details. 0N/A /* we can retry with the current credentials */ 0N/A /* header not used for ntlm */ 0N/A // cache server authentication info 0N/A // cache auth info on success 0N/A // check if the path is shorter than the existing entry 0N/A /* npath is longer, there must be a common root */ 0N/A // remove the entry and create a new one 0N/A // what we cache is based on the domain list in the request 0N/A /* path could be an abs_path or a complete URI */ 0N/A // some flags should be reset to its initialized form so that 0N/A // even after a redirect the necessary checks can still be 0N/A //serverAuthentication = null; 0N/A // a flag need to clean 0N/A /* if we should follow a redirect, then the followRedirects() 0N/A * method will disconnect() and re-connect us to the new 0N/A // redirecting HTTP response may have set cookie, so 0N/A // need to re-generate request header 0N/A // give cache a chance to save response in cache 0N/A // use reflection to get to the public 0N/A // HttpsURLConnection instance saved in 0N/A // DelegateHttpsURLConnection 0N/A // ignored; use 'this' 0N/A // ignored; use 'this' 0N/A // buffer the error stream if bytes < 4k 0N/A // and it can be buffered within 1 second 0N/A * Creates a chained exception that has the same type as 0N/A * original exception and with the same message. Right now, 0N/A * there is no convenient APIs for doing so. 0N/A // Client Error 4xx and Server Error 5xx 0N/A * set or reset proxy authentication info in request headers 0N/A * after receiving a 407 error. In the case of NTLM however, 0N/A * receiving a 407 is normal and we just skip the stale check 0N/A * because ntlm does not support this feature. 0N/A /* we can retry with the current credentials */ 256N/A * Returns the tunnel state. 256N/A * Set the tunneling status. 0N/A * establish a tunnel through proxy server 0N/A // save current requests so that they can be restored after tunnel is setup. 0N/A // Read comments labeled "Failed Negotiate" for details. 256N/A /* Actively setting up a tunnel */ 0N/A // send the "CONNECT" request to establish a tunnel 0N/A // through proxy server 0N/A // There is no need to track progress in HTTP Tunneling, 0N/A // so ProgressSource is null. 255N/A /* Log the response to the CONNECT */ 0N/A // Read comments labeled "Failed Negotiate" for details. 0N/A // cache proxy authentication info 0N/A // cache auth info on success, domain header not relevant. 0N/A // we don't know how to deal with other response code 0N/A // so disconnect and report error 0N/A " Proxy returns \"" +
0N/A // restore original request headers 0N/A * send a CONNECT request for establishing a tunnel to proxy server 0N/A // Not really necessary for a tunnel, but can't hurt 255N/A /* Log the CONNECT request */ 0N/A * Sets pre-emptive proxy authentication in header 0N/A // Sets "Proxy-authorization" 0N/A * Gets the authentication for an HTTP proxy, and applies it to 0N/A /* get authorization from authenticator */ 0N/A // User will have an unknown host. 1670N/A /* tryTransparentNTLMProxy will always be true the first 1670N/A * time around, but verify that the platform supports it 1670N/A /* If we are not trying transparent authentication then 1670N/A * we need to have a PasswordAuthentication instance. For 1670N/A * transparent authentication (Windows only) the username 1670N/A * and password will be picked up from the current logged 1670N/A /* set to false so that we do not try again */ 0N/A // For backwards compatibility, we also try defaultAuth 0N/A // REMIND: Get rid of this for JDK2.0. 0N/A // not in cache by default - cache on success 0N/A * Gets the authentication for an HTTP server, and applies it to 0N/A * @param authHdr the AuthenticationHeader which tells what auth scheme is 0N/A /* get authorization from authenticator */ 0N/A /* When we get an NTLM auth from cache, don't set any special headers */ 0N/A // User will have addr = null 0N/A // replacing -1 with default port for a protocol 1670N/A /* tryTransparentNTLMServer will always be true the first 1670N/A * time around, but verify that the platform supports it 3786N/A /* If the platform supports transparent authentication 3786N/A * then check if we are in a secure environment 3786N/A * whether, or not, we should try transparent authentication.*/ 1670N/A /* If we are not trying transparent authentication then 1670N/A * we need to have a PasswordAuthentication instance. For 1670N/A * transparent authentication (Windows only) the username 1670N/A * and password will be picked up from the current logged 1670N/A /* set to false so that we do not try again */ 0N/A // For backwards compatibility, we also try defaultAuth 0N/A // REMIND: Get rid of this for JDK2.0. 0N/A // not in cache by default - cache on success 0N/A /* inclose will be true if called from close(), in which case we 0N/A * force the call to check because this is the last chance to do so. 0N/A * If not in close(), then the authentication info could arrive in a trailer 0N/A * field, which we have not read yet. 1710N/A /* The request URI used in the request line for this request. 1710N/A * Also, needed for digest authentication 0N/A /* Tells us whether to follow a redirect. If so, it 0N/A * closes the connection (break any keep-alive) and 0N/A * resets the url, re-connects, and resets the request 0N/A /* this should be present - if not, we have no choice 0N/A * but to go forward w/ the response we got 0N/A // treat loc as a relative URI to conform to popular browsers 0N/A // clear out old response headers!!!! 0N/A /* This means we must re-request the resource through the 0N/A * proxy denoted in the "Location:" field of the response. 0N/A * Judging by the spec, the string in the Location header 0N/A * Make a new HttpClient to the proxy, using HttpClient's 0N/A * Instance-specific proxy fields, but note we're still fetching 0N/A // maintain previous headers, just change the name 0N/A // of the file we're getting 0N/A /* The HTTP/1.1 spec says that a redirect from a POST 0N/A * *should not* be immediately turned into a GET, and 0N/A * that some HTTP/1.0 clients incorrectly did this. 0N/A * Correct behavior redirects a POST to another POST. 0N/A * Unfortunately, since most browsers have this incorrect 0N/A * behavior, the web works this way now. Typical usage 0N/A * POST a login code or passwd to a web page. 0N/A * after validation, the server redirects to another 0N/A * The second request is (erroneously) expected to be GET 0N/A * We will do the incorrect thing (POST-->GET) by default. 0N/A * We will provide the capability to do the "right" thing 0N/A * (POST-->POST) by a system property, "http.strictPostRedirect=true" 0N/A /* Even after a connect() call, http variable still can be 0N/A * null, if a ResponseCache has been installed and it returns 0N/A * a non-null CacheResponse instance. So check nullity before using it. 0N/A * And further, if http is null, there's no need to do anything 0N/A * about request headers because successive http session will use 0N/A /* dummy byte buffer for reading off socket prior to closing */ 0N/A * Reset (without disconnecting the TCP conn) in order to do another transaction with this instance 0N/A /* must save before calling close */ 0N/A /* we want to read the rest of the response without using the 0N/A * hurry mechanism, because that would close the connection 0N/A * if everything is not available immediately 0N/A /* reading until eof will not block */ 0N/A /* raw stream, which will block on read, so only read 0N/A * the expected number of bytes, probably 0 2240N/A * Disconnect from the web server at the first 401 error. Do not 2240N/A * disconnect when using a proxy, a good proxy should have already 2240N/A * closed the connection to the web server. 2240N/A // clean up, particularly, skip the content part 0N/A * Disconnect from the server (for internal use) 0N/A * Disconnect from the server (public API) 0N/A * If we have an input stream this means we received a response 0N/A * from the server. That stream may have been read to EOF and 0N/A * dependening on the stream type may already be closed or the 0N/A * the http client may be returned to the keep-alive cache. 0N/A * If the http client has been returned to the keep-alive cache 0N/A * it may be closed (idle timeout) or may be allocated to 0N/A * In other to avoid timing issues we close the input stream 0N/A * which will either close the underlying connection or return 0N/A * the client to the cache. If there's a possibility that the 0N/A * client has been returned to the cache (ie: stream is a keep 0N/A * alive stream or a chunked input stream) then we remove an 0N/A * idle connection to the server. Note that this approach 0N/A * can be considered an approximation in that we may close a 0N/A * different idle connection to that used by the request. 0N/A * Additionally it's possible that we close two connections 0N/A * - the first becuase it wasn't an EOF (and couldn't be 0N/A * hurried) - the second, another idle connection to the 0N/A * same server. The is okay because "disconnect" is an 0N/A * indication that the application doesn't intend to access 0N/A * this http server for a while. 0N/A // if the connection is persistent it may have been closed 0N/A // or returned to the keep-alive cache. If it's been returned 0N/A // to the keep-alive cache then we would like to close it 0N/A // but it may have been allocated 0N/A // We are deliberatly being disconnected so HttpClient 0N/A // should not try to resend the request no matter what stage 0N/A // of the connection we are in. 4566N/A // constant strings represent set-cookie header names 4566N/A * Returns a filtered version of the given headers value. 4566N/A * Note: The implementation currently only filters out HttpOnly cookies 4566N/A * from Set-Cookie and Set-Cookie2 headers. 4566N/A // Filtering only if there is a cookie handler. [Assumption: the 4566N/A // Cache the filtered response headers so that they don't need 4566N/A // to be generated for every getHeaderFields() call. 0N/A * Gets a header field by name. Returns null if not known. 0N/A * @param name the name of the header field 0N/A * Returns an unmodifiable Map of the header fields. 0N/A * The Map keys are Strings that represent the 0N/A * response-header field names. Each Map value is an 0N/A * unmodifiable List of Strings that represents 0N/A * the corresponding field values. 0N/A * @return a Map of header fields 0N/A * Gets a header field by index. Returns null if not known. 0N/A * @param n the index of the header field 0N/A * Gets a header field by index. Returns null if not known. 0N/A * @param n the index of the header field 0N/A * Sets request property. If a property with the key already 0N/A * exists, overwrite its value with the new value. 0N/A * @param value the value to be set 0N/A * Adds a general request property specified by a 0N/A * key-value pair. This method will not overwrite 0N/A * existing values associated with the same key. 0N/A * @param key the keyword by which the request is known 0N/A * (e.g., "<code>accept</code>"). 0N/A * @param value the value associated with it. 0N/A * @see #getRequestProperties(java.lang.String) 0N/A // Set a property for authentication. This can safely disregard 0N/A // the connected test. 0N/A // don't return headers containing security sensitive information 0N/A * Returns an unmodifiable Map of general request 0N/A * properties for this connection. The Map keys 0N/A * are Strings that represent the request-header 0N/A * field names. Each Map value is a unmodifiable List 0N/A * of Strings that represents the corresponding 0N/A * @return a Map of the general request properties for this connection. 0N/A * @throws IllegalStateException if already connected 0N/A // exclude headers containing security-sensitive info 2910N/A * The cookies in the requests message headers may have 2910N/A * been modified. Use the saved user cookies instead. 0N/A * Returns setting for connect timeout. 0N/A * 0 return implies that the option is disabled 0N/A * (i.e., timeout of infinity). 0N/A * @return an <code>int</code> that indicates the connect timeout 0N/A * value in milliseconds 0N/A * @see java.net.URLConnection#setConnectTimeout(int) 0N/A * @see java.net.URLConnection#connect() 0N/A * Sets the read timeout to a specified timeout, in 0N/A * milliseconds. A non-zero value specifies the timeout when 0N/A * reading from Input stream when a connection is established to a 0N/A * resource. If the timeout expires before there is data available 0N/A * for read, a java.net.SocketTimeoutException is raised. A 0N/A * timeout of zero is interpreted as an infinite timeout. 0N/A * <p> Some non-standard implementation of this method ignores the 0N/A * specified timeout. To see the read timeout set, please call 0N/A * @param timeout an <code>int</code> that specifies the timeout 0N/A * value to be used in milliseconds 0N/A * @throws IllegalArgumentException if the timeout parameter is negative 0N/A * @see java.net.URLConnectiongetReadTimeout() 0N/A * @see java.io.InputStream#read() 0N/A * Returns setting for read timeout. 0 return implies that the 0N/A * option is disabled (i.e., timeout of infinity). 0N/A * @return an <code>int</code> that indicates the read timeout 0N/A * value in milliseconds 0N/A * @see java.net.URLConnection#setReadTimeout(int) 0N/A * @see java.io.InputStream#read() 0N/A /* The purpose of this wrapper is just to capture the close() call 0N/A * so we can check authentication information that may have 0N/A * arrived in a Trailer field 0N/A * Marks the current position in this input stream. A subsequent 0N/A * call to the <code>reset</code> method repositions this stream at 0N/A * the last marked position so that subsequent reads re-read the same 0N/A * The <code>readlimit</code> argument tells this input stream to 0N/A * allow that many bytes to be read before the mark position gets 0N/A * This method simply performs <code>in.mark(readlimit)</code>. 0N/A * @param readlimit the maximum limit of bytes that can be read before 0N/A * the mark position becomes invalid. 0N/A * @see java.io.FilterInputStream#in 0N/A * @see java.io.FilterInputStream#reset() 0N/A * Repositions this stream to the position at the time the 0N/A * <code>mark</code> method was last called on this input stream. 0N/A * simply performs <code>in.reset()</code>. 0N/A * Stream marks are intended to be used in 0N/A * situations where you need to read ahead a little to see what's in 0N/A * the stream. Often this is most easily done by invoking some 0N/A * general parser. If the stream is of the type handled by the 0N/A * parse, it just chugs along happily. If the stream is not of 0N/A * that type, the parser should toss an exception when it fails. 0N/A * If this happens within readlimit bytes, it allows the outer 0N/A * code to reset the stream and try another parser. 0N/A * @exception IOException if the stream has not been marked or if the 0N/A * mark has been invalidated. 0N/A * @see java.io.FilterInputStream#in 0N/A * @see java.io.FilterInputStream#mark(int) 0N/A byte[] b =
new byte[
1];
2816N/A /* skip() calls read() in order to ensure that entire response gets 2816N/A * cached. same implementation as InputStream.skip */ 0N/A * expectedLength == -1 if the stream is chunked 0N/A * expectedLength > 0 if the stream is fixed content-length 0N/A * In the 2nd case, we make sure the expected number of 0N/A * of bytes are actually written 0N/A /* this is called to check that all the bytes 0N/A * that were supposed to be written were written 0N/A * and that the stream is now closed(). 0N/A super.
flush();
/* can't close the socket */ 0N/A super.
close ();
/* force final chunk to be written */ 0N/A // when this method is called, it's either the case that cl > 0, or 0N/A // if chunk-encoded, cl = -1; in other words, cl can't be 0 0N/A // cl can't be 0; this following is here for extra precaution 0N/A // set SO_TIMEOUT to 1/5th of the total timeout 0N/A // remember the old timeout value so that we can restore it 0N/A // if chunked ended prematurely, 0N/A // an IOException would be thrown 0N/A // the server sends less than cl bytes of data 0N/A // reset SO_TIMEOUT to old value 0N/A // if count < cl at this point, we will not try to reuse 0N/A // since we haven't read anything, 0N/A // we will return the underlying 0N/A // inputstream back to the application 0N/A // put the connection into keep-alive cache 0N/A // the inputstream will try to do the right thing 0N/A // we read part of the response body 0N/A // ioex.printStackTrace(); 0N/A byte[] b =
new byte[
1];
0N/A/** An input stream that just returns EOF. This is for 0N/A * HTTP URLConnections that are KeepAlive && use the 0N/A * HEAD method - i.e., stream not dead, but nothing to be read.