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

bugfix issue #152 plus test case #203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion hyper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ def set_request_data(args):
body, headers, params = {}, {}, {}
for i in args.items:
if i.sep == SEP_HEADERS:
headers[i.key] = i.value
# :key:value case
if i.key == '':
k, v = i.value.split(':')
headers[':' + k] = v
else:
headers[i.key] = i.value
elif i.sep == SEP_QUERY:
params[i.key] = i.value
elif i.sep == SEP_DATA:
Expand Down
12 changes: 11 additions & 1 deletion hyper/packages/hpack/hpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,24 @@ def encode(self, headers, huffman=True):
representation: the same is true if they are in the static table.
Otherwise, a literal representation will be used.
"""
log.debug("HPACK encoding %s", headers)
header_block = []

# Turn the headers into a list of tuples if possible. This is the
# natural way to interact with them in HPACK.
if isinstance(headers, dict):
headers = headers.items()

# special headers need to come first in the header block
headers_helper = []
for h in headers:
if h[0][0] == ':':
headers_helper = [h] + headers_helper
else:
headers_helper.append(h)
headers = headers_helper

log.debug("HPACK encoding %s", headers)

# Next, walk across the headers and turn them all into bytestrings.
headers = [(_to_bytes(n), _to_bytes(v)) for n, v in headers]

Expand Down
9 changes: 9 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,20 @@ def test_cli_with_system_exit(argv):
{'method': 'GET', 'url.path': '/?param=test'}),
(['POST', 'example.com', 'data=test'],
{'method': 'POST', 'body': '{"data": "test"}'}),
(['GET', 'example.com', ':authority:example.org'],
{'method': 'GET', 'headers': {
':authority': 'example.org'}}),
(['GET', 'example.com', ':authority:example.org', 'x-test:header'],
{'method': 'GET', 'headers': {
':authority': 'example.org',
'x-test':'header'}}),
], ids=[
'specified "--debug" option',
'specified host and additional header',
'specified host and get parameter',
'specified host and post data',
'specified host and override default header',
'specified host and override default header and additional header',
])
def test_parse_argument(argv, expected):
args = parse_argument(argv)
Expand Down