Fixed problem with proxy server sometimes responds with 400 Bad Request when trying

to connect to a site using https.

The CONNECT to the server lacks the 'host' header which is mandatory according to the
specification. Some proxy servers are strictly following the specification and sends
back the 400 Bad Requst error code.
This commit is contained in:
Henrik Baard
2010-02-24 08:41:48 +01:00
committed by Johan Redestig
parent 27f3de6bac
commit ea4e597a87

View File

@@ -202,10 +202,13 @@ public class HttpsConnection extends Connection {
BasicHttpRequest proxyReq = new BasicHttpRequest
("CONNECT", mHost.toHostString());
// add all 'proxy' headers from the original request
// add all 'proxy' headers from the original request, we also need
// to add 'host' header unless we want proxy to answer us with a
// 400 Bad Request
for (Header h : req.mHttpRequest.getAllHeaders()) {
String headerName = h.getName().toLowerCase();
if (headerName.startsWith("proxy") || headerName.equals("keep-alive")) {
if (headerName.startsWith("proxy") || headerName.equals("keep-alive")
|| headerName.equals("host")) {
proxyReq.addHeader(h);
}
}