From ea4e597a87b51b8ec19798f3fdedf74a723d75d8 Mon Sep 17 00:00:00 2001 From: Henrik Baard Date: Wed, 24 Feb 2010 08:41:48 +0100 Subject: [PATCH] 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. --- core/java/android/net/http/HttpsConnection.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/http/HttpsConnection.java b/core/java/android/net/http/HttpsConnection.java index 8a69d0d9fdff6..0163482b053a5 100644 --- a/core/java/android/net/http/HttpsConnection.java +++ b/core/java/android/net/http/HttpsConnection.java @@ -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); } }