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

Commit 17c2305

Browse files
committed
Add http upgrade headers only sent once test
1 parent ed0067c commit 17c2305

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

hyper/http11/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(self, host, port=None, secure=None, ssl_context=None,
6969
else:
7070
self.secure = False
7171

72+
# only send http upgrade headers for non-secure connection
7273
self._send_http_upgrade = not self.secure
7374

7475
self.ssl_context = ssl_context
@@ -133,7 +134,7 @@ def request(self, method, url, body=None, headers={}):
133134

134135
if self._sock is None:
135136
self.connect()
136-
137+
137138
if(self._send_http_upgrade):
138139
self._add_upgrade_headers(headers)
139140
self._send_http_upgrade = False

test/test_http11.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,24 @@ def body():
334334
body=body()
335335
)
336336

337+
def test_http_upgrade_headers_only_sent_once(self):
338+
c = HTTP11Connection('httpbin.org')
339+
c._sock = sock = DummySocket()
340+
341+
c.request('GET', '/get', headers={'User-Agent': 'hyper'})
342+
343+
sock.queue = []
344+
c.request('GET', '/get', headers={'User-Agent': 'hyper'})
345+
received = b''.join(sock.queue)
346+
347+
expected = (
348+
b"GET /get HTTP/1.1\r\n"
349+
b"User-Agent: hyper\r\n"
350+
b"host: httpbin.org\r\n"
351+
b"\r\n"
352+
)
353+
354+
assert received == expected
337355

338356
class TestHTTP11Response(object):
339357
def test_short_circuit_read(self):

0 commit comments

Comments
 (0)