{"action":"opened","issue":{"url":"https://api.github.com/repos/hyperium/hyper/issues/774","repository_url":"https://api.github.com/repos/hyperium/hyper","labels_url":"https://api.github.com/repos/hyperium/hyper/issues/774/labels{/name}","comments_url":"https://api.github.com/repos/hyperium/hyper/issues/774/comments","events_url":"https://api.github.com/repos/hyperium/hyper/issues/774/events","html_url":"https://github.com/hyperium/hyper/issues/774","id":151432130,"number":774,"title":"Proxy handling does not properly set destination Host header","user":{"login":"shaleh","id":1377996,"avatar_url":"https://avatars.githubusercontent.com/u/1377996?v=3","gravatar_id":"","url":"https://api.github.com/users/shaleh","html_url":"https://github.com/shaleh","followers_url":"https://api.github.com/users/shaleh/followers","following_url":"https://api.github.com/users/shaleh/following{/other_user}","gists_url":"https://api.github.com/users/shaleh/gists{/gist_id}","starred_url":"https://api.github.com/users/shaleh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shaleh/subscriptions","organizations_url":"https://api.github.com/users/shaleh/orgs","repos_url":"https://api.github.com/users/shaleh/repos","events_url":"https://api.github.com/users/shaleh/events{/privacy}","received_events_url":"https://api.github.com/users/shaleh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-27T16:39:51Z","updated_at":"2016-04-27T16:39:51Z","closed_at":null,"body":"Here is a script transcript of a working proxy session\r\n\r\n    Script started on Wed 27 Apr 2016 09:32:58 AM PDT\r\n    [~/repos/rust/hyper-upstream]\r\n    ~$ telnet my-proxy 8080\r\n    Trying x.x.x.x...\r\n    Connected to my-proxy.\r\n    Escape character is '^]'.\r\n    GET http://xkcd.com http/1.1\r\n    host: xkcd.com:80\r\n\r\n    HTTP/1.1 200 OK\r\n    Cache-Control: public, max-age=300\r\n    Expires: Wed, 27 Apr 2016 16:23:15 GMT\r\n    Content-Type: text/html; charset=utf-8\r\n    ETag: \"1703862119\"\r\n    Last-Modified: Wed, 27 Apr 2016 05:16:40 GMT\r\n    Server: lighttpd/1.4.28\r\n    Content-Length: 6196\r\n    Accept-Ranges: bytes\r\n    Date: Wed, 27 Apr 2016 16:18:15 GMT\r\n    Via: 1.1 varnish\r\n    X-Served-By: cache-dfw1838-DFW\r\n    X-Cache: HIT\r\n    X-Cache-Hits: 1\r\n    X-Timer: S1461772234.306036,VS0,VE0\r\n    Vary: Accept-Encoding\r\n    Proxy-Connection: Keep-Alive\r\n    Connection: Keep-Alive\r\n    Age: 971\r\n\r\nNote the destination is specified TWICE. Once on the GET and once again in the Host line. The current client code does not set the Host correctly.\r\n\r\nHere is the diff needed to fix it:\r\n\r\n    diff --git a/src/client/mod.rs b/src/client/mod.rs\r\n    index 4ad5c2d..ad0b14d 100644\r\n    --- a/src/client/mod.rs\r\n    +++ b/src/client/mod.rs\r\n    @@ -271,10 +271,10 @@ impl<'a> RequestBuilder<'a> {\r\n\r\n             loop {\r\n                 let mut req = {\r\n    +                let hp = try!(get_host_and_port(&url));\r\n                     let (scheme, host, port) = match client.proxy {\r\n                         Some(ref proxy) => (proxy.0.as_ref(), proxy.1.as_ref(), proxy.2),\r\n                         None => {\r\n    -                        let hp = try!(get_host_and_port(&url));\r\n                             (url.scheme(), hp.0, hp.1)\r\n                         }\r\n                     };\r\n    @@ -282,11 +282,14 @@ impl<'a> RequestBuilder<'a> {\r\n                         Some(ref headers) => headers.clone(),\r\n                         None => Headers::new(),\r\n                     };\r\n    +                // Host needs to be the destination host not the proxy\r\n                     headers.set(Host {\r\n    -                    hostname: host.to_owned(),\r\n    -                    port: Some(port),\r\n    +                    hostname: hp.0.to_owned(),\r\n    +                    port: Some(hp.1),\r\n                     });\r\n    +                // now connect to the proxy\r\n                     let message = try!(client.protocol.new_message(&host, port, scheme));\r\n    +                // and make a request for the destination\r\n                     Request::with_headers_and_message(method.clone(), url.clone(), headers, messag\\\r\ne)\r\n                 };\r\n"}}