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

Commit b3bf52f

Browse files
committed
Allow non-dictionary header arguments in request method
1 parent e7ce870 commit b3bf52f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

hyper/http11/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import socket
1111
import base64
1212

13+
from collections import Iterable
14+
1315
from .response import HTTP11Response
1416
from ..tls import wrap_socket, H2C_PROTOCOL
1517
from ..common.bufsocket import BufferedSocket
@@ -148,7 +150,9 @@ def request(self, method, url, body=None, headers={}):
148150
url = to_bytestring(url)
149151

150152
if not isinstance(headers, HTTPHeaderMap):
151-
# FIXME: Handle things that aren't dictionaries here.
153+
if isinstance(headers, Iterable):
154+
headers = dict(headers)
155+
152156
headers = HTTPHeaderMap(headers.items())
153157

154158
if self._sock is None:

test/test_http11.py

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

125125
assert received == expected
126126

127+
def test_iterable_headers(self):
128+
c = HTTP11Connection('httpbin.org')
129+
c._sock = sock = DummySocket()
130+
131+
c.request('GET', '/get', headers=(('User-Agent', 'hyper'),))
132+
133+
expected = (
134+
b"GET /get HTTP/1.1\r\n"
135+
b"User-Agent: hyper\r\n"
136+
b"connection: Upgrade, HTTP2-Settings\r\n"
137+
b"upgrade: h2c\r\n"
138+
b"HTTP2-Settings: AAQAAP//\r\n"
139+
b"host: httpbin.org\r\n"
140+
b"\r\n"
141+
)
142+
received = b''.join(sock.queue)
143+
144+
assert received == expected
145+
127146
def test_proxy_request(self):
128147
c = HTTP11Connection('httpbin.org', proxy_host='localhost')
129148
c._sock = sock = DummySocket()

0 commit comments

Comments
 (0)