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

Commit 7aa2201

Browse files
committed
Merge pull request #205 from pkrolikowski/development
Enable override default headers from CLI
2 parents 6be7831 + e509c7a commit 7aa2201

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

hyper/cli.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,14 @@ def set_request_data(args):
164164
body, headers, params = {}, {}, {}
165165
for i in args.items:
166166
if i.sep == SEP_HEADERS:
167-
headers[i.key] = i.value
167+
if i.key:
168+
headers[i.key] = i.value
169+
else:
170+
# when overriding a HTTP/2 special header there will be a leading
171+
# colon, which tricks the command line parser into thinking
172+
# the header is empty
173+
k, v = i.value.split(':', 1)
174+
headers[':' + k] = v
168175
elif i.sep == SEP_QUERY:
169176
params[i.key] = i.value
170177
elif i.sep == SEP_DATA:

test/test_cli.py

+9
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,20 @@ def test_cli_with_system_exit(argv):
110110
{'method': 'GET', 'url.path': '/?param=test'}),
111111
(['POST', 'example.com', 'data=test'],
112112
{'method': 'POST', 'body': '{"data": "test"}'}),
113+
(['GET', 'example.com', ':authority:example.org'],
114+
{'method': 'GET', 'headers': {
115+
':authority': 'example.org'}}),
116+
(['GET', 'example.com', ':authority:example.org', 'x-test:header'],
117+
{'method': 'GET', 'headers': {
118+
':authority': 'example.org',
119+
'x-test':'header'}}),
113120
], ids=[
114121
'specified "--debug" option',
115122
'specified host and additional header',
116123
'specified host and get parameter',
117124
'specified host and post data',
125+
'specified host and override default header',
126+
'specified host and override default header and additional header',
118127
])
119128
def test_parse_argument(argv, expected):
120129
args = parse_argument(argv)

0 commit comments

Comments
 (0)