Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit a2af966

Browse files
committed
Add tests to ensure enabling proxy doesnt hit host header
1 parent e221dda commit a2af966

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

test/test_http11.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ def test_basic_request(self):
116116

117117
assert received == expected
118118

119+
def test_proxy_request(self):
120+
c = HTTP11Connection('httpbin.org', proxy_host='localhost')
121+
c._sock = sock = DummySocket()
122+
123+
c.request('GET', '/get', headers={'User-Agent': 'hyper'})
124+
125+
expected = (
126+
b"GET /get HTTP/1.1\r\n"
127+
b"User-Agent: hyper\r\n"
128+
b"connection: Upgrade, HTTP2-Settings\r\n"
129+
b"upgrade: h2c\r\n"
130+
b"HTTP2-Settings: AAQAAP//\r\n"
131+
b"host: httpbin.org\r\n"
132+
b"\r\n"
133+
)
134+
received = b''.join(sock.queue)
135+
136+
assert received == expected
137+
119138
def test_request_with_bytestring_body(self):
120139
c = HTTP11Connection('httpbin.org')
121140
c._sock = sock = DummySocket()

test/test_hyper.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,19 @@ def data_cb(frame, *args):
483483
assert frames[0].type == WindowUpdateFrame.type
484484
assert frames[0].window_increment == 5535
485485

486+
def test_that_using_proxy_keeps_http_headers_intact(self):
487+
sock = DummySocket()
488+
c = HTTP20Connection('www.google.com', secure=False, proxy_host='localhost')
489+
c._sock = sock
490+
c.request('GET', '/')
491+
s = c.recent_stream
492+
493+
assert s.headers == [
494+
(':method', 'GET'),
495+
(':scheme', 'http'),
496+
(':authority', 'www.google.com'),
497+
(':path', '/'),
498+
]
486499

487500
class TestServerPush(object):
488501
def setup_method(self, method):

0 commit comments

Comments
 (0)