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

Commit fbd7e4c

Browse files
committed
Upcase method only from CLI
- Remove upcasing method at connection level
1 parent d947c6c commit fbd7e4c

File tree

8 files changed

+6
-41
lines changed

8 files changed

+6
-41
lines changed

hyper/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def set_request_data(args):
195195
if args.method is None:
196196
args.method = 'POST' if args.body else 'GET'
197197

198+
args.method = args.method.upper()
198199
args.headers = headers
199200

200201

hyper/common/connection.py

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

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

hyper/http11/connection.py

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

155155
method = to_bytestring(method)
156-
upcased_method = method.upper()
157156
url = to_bytestring(url)
158157

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

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

186185
# Next, send the request body.
187186
if body:

hyper/http20/connection.py

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

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

test/test_abstraction.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ 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-
4841
def test_tls_upgrade(self, monkeypatch):
4942
monkeypatch.setattr(
5043
hyper.common.connection, 'HTTP11Connection', DummyH1Connection

test/test_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_cli_with_system_exit(argv):
104104

105105
@pytest.mark.parametrize(('argv', 'expected'), [
106106
(['--debug', 'example.com'], {'debug': True}),
107+
(['get', 'example.com'], {'method': 'GET'}),
107108
(['GET', 'example.com', 'x-test:header'],
108109
{'method': 'GET', 'headers': {'x-test': 'header'}}),
109110
(['GET', 'example.com', 'param==test'],
@@ -119,6 +120,7 @@ def test_cli_with_system_exit(argv):
119120
'x-test': 'header'}}),
120121
], ids=[
121122
'specified "--debug" option',
123+
'specify host with lower get method',
122124
'specified host and additional header',
123125
'specified host and get parameter',
124126
'specified host and post data',

test/test_http11.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,6 @@ 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-
150131
def test_iterable_header(self):
151132
c = HTTP11Connection('httpbin.org')
152133
c._sock = sock = DummySocket()

test/test_hyper.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,6 @@ 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-
10192
def test_putrequest_autosets_headers(self):
10293
c = HTTP20Connection("www.google.com")
10394

0 commit comments

Comments
 (0)