/** cache for resolveAndCheckIfFirewalled() */
static Hashtable resolvedHosts = new Hashtable();
- /** if any request encounters an IOException, the entire HTTP connection is invalidated */
- boolean invalid = false;
-
/** true iff we are allowed to skip the resolve check (only allowed when we're downloading the PAC script) */
boolean skipResolveCheck = false;
Semaphore blockOn = null;
Semaphore releaseMe = null;
synchronized(this) {
- if (invalid) throw new HTTPException("connection failed on a previous pipelined call");
try {
connect();
sendRequest(contentType, content);
} catch (IOException e) {
- invalid = true;
+ sock = null;
+ in = null;
throw e;
}
blockOn = okToRecieve;
boolean doRelease = true;
try {
if (blockOn != null) blockOn.block();
- if (invalid) throw new HTTPException("connection failed on a previous pipelined call");
+
+ // previous call wrecked the socket connection, but we already sent our request, so we can't just retry --
+ // this could cause the server to receive the request twice, which could be bad (think of the case where the
+ // server call causes Amazon.com to ship you an item with one-click purchasing).
+ if (sock == null)
+ throw new HTTPException("a previous pipelined call messed up the socket");
Hashtable h = in == null ? null : parseHeaders(in);
if (h == null) {
}
- } catch (IOException e) { invalid = true; throw e;
+ } catch (IOException e) { sock = null; in = null; throw e;
} finally { if (doRelease) releaseMe.release();
}
}
if (Log.verbose) Log.log(this, "creating HTTP object for connection to " + host + ":" + port);
Proxy pi = Platform.detectProxy();
- if (sock == null && pi != null && pi.proxyAutoConfigFunction != null) sock = attemptPAC(pi.proxyAutoConfigFunction);
- if (sock == null && pi != null && ssl && pi.httpsProxyHost != null) sock = attemptHttpProxy(pi.httpsProxyHost, pi.httpsProxyPort);
- if (sock == null && pi != null && pi.httpProxyHost != null) sock = attemptHttpProxy(pi.httpProxyHost, pi.httpProxyPort);
- if (sock == null && pi != null && pi.socksProxyHost != null) sock = attemptSocksProxy(pi.socksProxyHost, pi.socksProxyPort);
+ OUTER: do {
+ if (pi != null) {
+ for(int i=0; i<pi.excluded.length; i++) if (host.equals(pi.excluded[i])) break OUTER;
+ if (sock == null && pi.proxyAutoConfigFunction != null) sock = attemptPAC(pi.proxyAutoConfigFunction);
+ if (sock == null && ssl && pi.httpsProxyHost != null) sock = attemptHttpProxy(pi.httpsProxyHost, pi.httpsProxyPort);
+ if (sock == null && pi.httpProxyHost != null) sock = attemptHttpProxy(pi.httpProxyHost, pi.httpProxyPort);
+ if (sock == null && pi.socksProxyHost != null) sock = attemptSocksProxy(pi.socksProxyHost, pi.socksProxyPort);
+ }
+ } while (false);
proxied = sock != null;
if (sock == null) sock = attemptDirect();
if (sock == null) throw new HTTPException("unable to contact host " + host);
}
return ret;
} finally {
- if (!good) invalid = true;
+ if (!good) { HTTP.this.sock = null; HTTP.this.in = null; }
}
}