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

Commit d947c6c

Browse files
committed
Convert HTTP method to upper case
1 parent 73d04f1 commit d947c6c

File tree

6 files changed

+41
-4
lines changed

6 files changed

+41
-4
lines changed

hyper/common/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ def request(self, method, url, body=None, headers=None):
9999
headers = headers or {}
100100

101101
try:
102+
upcased_method = method.upper()
102103
return self._conn.request(
103-
method=method, url=url, body=body, headers=headers
104+
method=upcased_method, url=url, body=body, headers=headers
104105
)
105106
except TLSUpgrade as e:
106107
# We upgraded in the NPN/ALPN handshake. We can just go straight to

hyper/http11/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def request(self, method, url, body=None, headers=None):
153153
headers = headers or {}
154154

155155
method = to_bytestring(method)
156+
upcased_method = method.upper()
156157
url = to_bytestring(url)
157158

158159
if not isinstance(headers, HTTPHeaderMap):
@@ -180,7 +181,7 @@ def request(self, method, url, body=None, headers=None):
180181
headers[b'host'] = self.host
181182

182183
# Begin by emitting the header block.
183-
self._send_headers(method, url, headers)
184+
self._send_headers(upcased_method, url, headers)
184185

185186
# Next, send the request body.
186187
if body:

hyper/http20/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def request(self, method, url, body=None, headers=None):
235235
:returns: A stream ID for the request.
236236
"""
237237
headers = headers or {}
238-
238+
upcased_method = method.upper()
239239
# Concurrency
240240
#
241241
# It's necessary to hold a lock while this method runs to satisfy H2
@@ -248,7 +248,7 @@ def request(self, method, url, body=None, headers=None):
248248
# being sent in the wrong order, which can lead to the out-of-order
249249
# messages with lower stream IDs being closed prematurely.
250250
with self._write_lock:
251-
stream_id = self.putrequest(method, url)
251+
stream_id = self.putrequest(upcased_method, url)
252252

253253
default_headers = (':method', ':scheme', ':authority', ':path')
254254
for name, value in headers.items():

test/test_abstraction.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def test_h2_kwargs(self):
3838
'other_kwarg': True,
3939
}
4040

41+
def test_get_method_with_lower_case(self):
42+
conn = HTTPConnection('http2bin.org:443')
43+
conn.request('get', '/get')
44+
resp = conn.get_response()
45+
46+
assert resp.status == 200
47+
4148
def test_tls_upgrade(self, monkeypatch):
4249
monkeypatch.setattr(
4350
hyper.common.connection, 'HTTP11Connection', DummyH1Connection

test/test_http11.py

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

129129
assert received == expected
130130

131+
def test_basic_request_with_lower_case_method(self):
132+
c = HTTP11Connection('httpbin.org')
133+
c._sock = sock = DummySocket()
134+
135+
c.request('get', '/get', headers={'User-Agent': 'hyper'})
136+
137+
expected = (
138+
b"GET /get HTTP/1.1\r\n"
139+
b"User-Agent: hyper\r\n"
140+
b"connection: Upgrade, HTTP2-Settings\r\n"
141+
b"upgrade: h2c\r\n"
142+
b"HTTP2-Settings: AAQAAP__\r\n"
143+
b"host: httpbin.org\r\n"
144+
b"\r\n"
145+
)
146+
received = b''.join(sock.queue)
147+
148+
assert received == expected
149+
131150
def test_iterable_header(self):
132151
c = HTTP11Connection('httpbin.org')
133152
c._sock = sock = DummySocket()

test/test_hyper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def test_putrequest_establishes_new_stream(self):
8989
assert len(c.streams) == 1
9090
assert c.recent_stream is stream
9191

92+
def test_putrequest_establishes_new_stream_with_lower_case_method(self):
93+
c = HTTP20Connection("www.google.com")
94+
95+
stream_id = c.putrequest('get', '/')
96+
stream = c.streams[stream_id]
97+
98+
assert len(c.streams) == 1
99+
assert c.recent_stream is stream
100+
92101
def test_putrequest_autosets_headers(self):
93102
c = HTTP20Connection("www.google.com")
94103

0 commit comments

Comments
 (0)