388 * to send Content-type: <> and Content-length:<> second |
388 * to send Content-type: <> and Content-length:<> second |
389 * to last and last, respectively, in the case of a POST |
389 * to last and last, respectively, in the case of a POST |
390 * request. |
390 * request. |
391 */ |
391 */ |
392 if (!failedOnce) |
392 if (!failedOnce) |
393 requests.prepend(method + " " + http.getURLFile()+" " + |
393 requests.prepend(method + " " + getRequestURI()+" " + |
394 httpVersion, null); |
394 httpVersion, null); |
395 if (!getUseCaches()) { |
395 if (!getUseCaches()) { |
396 requests.setIfNotSet ("Cache-Control", "no-cache"); |
396 requests.setIfNotSet ("Cache-Control", "no-cache"); |
397 requests.setIfNotSet ("Pragma", "no-cache"); |
397 requests.setIfNotSet ("Pragma", "no-cache"); |
398 } |
398 } |
1544 proxyAuthentication.getAuthScheme() != NTLM) { |
1544 proxyAuthentication.getAuthScheme() != NTLM) { |
1545 String raw = auth.raw(); |
1545 String raw = auth.raw(); |
1546 if (proxyAuthentication.isAuthorizationStale (raw)) { |
1546 if (proxyAuthentication.isAuthorizationStale (raw)) { |
1547 /* we can retry with the current credentials */ |
1547 /* we can retry with the current credentials */ |
1548 String value; |
1548 String value; |
1549 if (tunnelState() == TunnelState.SETUP && |
1549 if (proxyAuthentication instanceof DigestAuthentication) { |
1550 proxyAuthentication instanceof DigestAuthentication) { |
1550 DigestAuthentication digestProxy = (DigestAuthentication) |
1551 value = ((DigestAuthentication)proxyAuthentication) |
1551 proxyAuthentication; |
1552 .getHeaderValue(connectRequestURI(url), HTTP_CONNECT); |
1552 if (tunnelState() == TunnelState.SETUP) { |
|
1553 value = digestProxy.getHeaderValue(connectRequestURI(url), HTTP_CONNECT); |
|
1554 } else { |
|
1555 value = digestProxy.getHeaderValue(getRequestURI(), method); |
|
1556 } |
1553 } else { |
1557 } else { |
1554 value = proxyAuthentication.getHeaderValue(url, method); |
1558 value = proxyAuthentication.getHeaderValue(url, method); |
1555 } |
1559 } |
1556 requests.set(proxyAuthentication.getHeaderName(), value); |
1560 requests.set(proxyAuthentication.getHeaderName(), value); |
1557 currentProxyCredentials = proxyAuthentication; |
1561 currentProxyCredentials = proxyAuthentication; |
1763 AuthenticationInfo pauth |
1767 AuthenticationInfo pauth |
1764 = AuthenticationInfo.getProxyAuth(http.getProxyHostUsed(), |
1768 = AuthenticationInfo.getProxyAuth(http.getProxyHostUsed(), |
1765 http.getProxyPortUsed()); |
1769 http.getProxyPortUsed()); |
1766 if (pauth != null && pauth.supportsPreemptiveAuthorization()) { |
1770 if (pauth != null && pauth.supportsPreemptiveAuthorization()) { |
1767 String value; |
1771 String value; |
1768 if (tunnelState() == TunnelState.SETUP && |
1772 if (pauth instanceof DigestAuthentication) { |
1769 pauth instanceof DigestAuthentication) { |
1773 DigestAuthentication digestProxy = (DigestAuthentication) pauth; |
1770 value = ((DigestAuthentication)pauth) |
1774 if (tunnelState() == TunnelState.SETUP) { |
|
1775 value = digestProxy |
1771 .getHeaderValue(connectRequestURI(url), HTTP_CONNECT); |
1776 .getHeaderValue(connectRequestURI(url), HTTP_CONNECT); |
|
1777 } else { |
|
1778 value = digestProxy.getHeaderValue(getRequestURI(), method); |
|
1779 } |
1772 } else { |
1780 } else { |
1773 value = pauth.getHeaderValue(url, method); |
1781 value = pauth.getHeaderValue(url, method); |
1774 } |
1782 } |
1775 |
1783 |
1776 // Sets "Proxy-authorization" |
1784 // Sets "Proxy-authorization" |
2073 */ |
2081 */ |
2074 private void checkResponseCredentials (boolean inClose) throws IOException { |
2082 private void checkResponseCredentials (boolean inClose) throws IOException { |
2075 try { |
2083 try { |
2076 if (!needToCheck) |
2084 if (!needToCheck) |
2077 return; |
2085 return; |
2078 if (validateProxy && currentProxyCredentials != null) { |
2086 if ((validateProxy && currentProxyCredentials != null) && |
|
2087 (currentProxyCredentials instanceof DigestAuthentication)) { |
2079 String raw = responses.findValue ("Proxy-Authentication-Info"); |
2088 String raw = responses.findValue ("Proxy-Authentication-Info"); |
2080 if (inClose || (raw != null)) { |
2089 if (inClose || (raw != null)) { |
2081 currentProxyCredentials.checkResponse (raw, method, url); |
2090 DigestAuthentication da = (DigestAuthentication) |
|
2091 currentProxyCredentials; |
|
2092 da.checkResponse (raw, method, getRequestURI()); |
2082 currentProxyCredentials = null; |
2093 currentProxyCredentials = null; |
2083 } |
2094 } |
2084 } |
2095 } |
2085 if (validateServer && currentServerCredentials != null) { |
2096 if ((validateServer && currentServerCredentials != null) && |
|
2097 (currentServerCredentials instanceof DigestAuthentication)) { |
2086 String raw = responses.findValue ("Authentication-Info"); |
2098 String raw = responses.findValue ("Authentication-Info"); |
2087 if (inClose || (raw != null)) { |
2099 if (inClose || (raw != null)) { |
2088 currentServerCredentials.checkResponse (raw, method, url); |
2100 DigestAuthentication da = (DigestAuthentication) |
|
2101 currentServerCredentials; |
|
2102 da.checkResponse (raw, method, url); |
2089 currentServerCredentials = null; |
2103 currentServerCredentials = null; |
2090 } |
2104 } |
2091 } |
2105 } |
2092 if ((currentServerCredentials==null) && (currentProxyCredentials == null)) { |
2106 if ((currentServerCredentials==null) && (currentProxyCredentials == null)) { |
2093 needToCheck = false; |
2107 needToCheck = false; |
2095 } catch (IOException e) { |
2109 } catch (IOException e) { |
2096 disconnectInternal(); |
2110 disconnectInternal(); |
2097 connected = false; |
2111 connected = false; |
2098 throw e; |
2112 throw e; |
2099 } |
2113 } |
|
2114 } |
|
2115 |
|
2116 /* The request URI used in the request line for this request. |
|
2117 * Also, needed for digest authentication |
|
2118 */ |
|
2119 |
|
2120 String requestURI = null; |
|
2121 |
|
2122 String getRequestURI() { |
|
2123 if (requestURI == null) { |
|
2124 try { |
|
2125 requestURI = http.getURLFile(); |
|
2126 } catch (IOException e) { |
|
2127 requestURI = ""; |
|
2128 } |
|
2129 } |
|
2130 return requestURI; |
2100 } |
2131 } |
2101 |
2132 |
2102 /* Tells us whether to follow a redirect. If so, it |
2133 /* Tells us whether to follow a redirect. If so, it |
2103 * closes the connection (break any keep-alive) and |
2134 * closes the connection (break any keep-alive) and |
2104 * resets the url, re-connects, and resets the request |
2135 * resets the url, re-connects, and resets the request |
2158 if (security != null) { |
2189 if (security != null) { |
2159 security.checkConnect(proxyHost, proxyPort); |
2190 security.checkConnect(proxyHost, proxyPort); |
2160 } |
2191 } |
2161 |
2192 |
2162 setProxiedClient (url, proxyHost, proxyPort); |
2193 setProxiedClient (url, proxyHost, proxyPort); |
2163 requests.set(0, method + " " + http.getURLFile()+" " + |
2194 requests.set(0, method + " " + getRequestURI()+" " + |
2164 httpVersion, null); |
2195 httpVersion, null); |
2165 connected = true; |
2196 connected = true; |
2166 } else { |
2197 } else { |
2167 // maintain previous headers, just change the name |
2198 // maintain previous headers, just change the name |
2168 // of the file we're getting |
2199 // of the file we're getting |
2169 url = locUrl; |
2200 url = locUrl; |
|
2201 requestURI = null; // force it to be recalculated |
2170 if (method.equals("POST") && !Boolean.getBoolean("http.strictPostRedirect") && (stat!=307)) { |
2202 if (method.equals("POST") && !Boolean.getBoolean("http.strictPostRedirect") && (stat!=307)) { |
2171 /* The HTTP/1.1 spec says that a redirect from a POST |
2203 /* The HTTP/1.1 spec says that a redirect from a POST |
2172 * *should not* be immediately turned into a GET, and |
2204 * *should not* be immediately turned into a GET, and |
2173 * that some HTTP/1.0 clients incorrectly did this. |
2205 * that some HTTP/1.0 clients incorrectly did this. |
2174 * Correct behavior redirects a POST to another POST. |
2206 * Correct behavior redirects a POST to another POST. |
2202 * about request headers because successive http session will use |
2234 * about request headers because successive http session will use |
2203 * cachedInputStream/cachedHeaders anyway, which is returned by |
2235 * cachedInputStream/cachedHeaders anyway, which is returned by |
2204 * CacheResponse. |
2236 * CacheResponse. |
2205 */ |
2237 */ |
2206 if (http != null) { |
2238 if (http != null) { |
2207 requests.set(0, method + " " + http.getURLFile()+" " + |
2239 requests.set(0, method + " " + getRequestURI()+" " + |
2208 httpVersion, null); |
2240 httpVersion, null); |
2209 int port = url.getPort(); |
2241 int port = url.getPort(); |
2210 String host = url.getHost(); |
2242 String host = url.getHost(); |
2211 if (port != -1 && port != url.getDefaultPort()) { |
2243 if (port != -1 && port != url.getDefaultPort()) { |
2212 host += ":" + String.valueOf(port); |
2244 host += ":" + String.valueOf(port); |