From a69d223b335894a5c9f7c006cf46a0cb4bc0ac43 Mon Sep 17 00:00:00 2001
From: Will Coster <willcoster@google.com>
Date: Mon, 15 Feb 2016 16:21:20 -0800
Subject: Preserve host header when modifying request path

Currently the path_components and query setters of the Request object
use the url setter under the hood. The url setter updates all parts of
the URL including the host. If the host header and the host in the
request URL are different (as is common when making HTTPS requests)
then the host header will be updated to the value in the URL as a
result of modifying the path.

This change fixes this problem by modifying the query and
path_components setters to not use the url setter and instead directly
update the path field.
---
 test/netlib/http/test_request.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'test/netlib/http/test_request.py')

diff --git a/test/netlib/http/test_request.py b/test/netlib/http/test_request.py
index 900b2cd1..7a6a9665 100644
--- a/test/netlib/http/test_request.py
+++ b/test/netlib/http/test_request.py
@@ -136,8 +136,10 @@ class TestRequestUtils(object):
         assert request.query.lst == [("bar", "42")]
 
     def test_set_query(self):
-        request = treq()
+        request = treq(host=b"foo", headers = Headers(host=b"bar"))
         request.query = ODict([])
+        assert request.host == b"foo"
+        assert request.headers["host"] == b"bar"
 
     def test_get_cookies_none(self):
         request = treq()
@@ -180,11 +182,14 @@ class TestRequestUtils(object):
         assert request.path_components == ["foo", "bar"]
 
     def test_set_path_components(self):
-        request = treq()
+        request = treq(host=b"foo", headers = Headers(host=b"bar"))
         request.path_components = ["foo", "baz"]
         assert request.path == "/foo/baz"
         request.path_components = []
         assert request.path == "/"
+        request.query = ODict([])
+        assert request.host == b"foo"
+        assert request.headers["host"] == b"bar"
 
     def test_anticache(self):
         request = treq()
-- 
cgit v1.2.3