From bb62f80367e68f23e62be893c5a5ac51b549da82 Mon Sep 17 00:00:00 2001 From: pkrolikowski Date: Mon, 22 Feb 2016 11:23:03 +0100 Subject: [PATCH 1/3] Enable override default headers from CLI --- hyper/cli.py | 7 ++++++- test/test_cli.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hyper/cli.py b/hyper/cli.py index 6eed9e10..90f68f25 100644 --- a/hyper/cli.py +++ b/hyper/cli.py @@ -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: diff --git a/test/test_cli.py b/test/test_cli.py index 7bae3f96..2928b2c6 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -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) From 095c50e1e40a5ede448dc3fe75b82bf23edc6768 Mon Sep 17 00:00:00 2001 From: pkrolikowski Date: Mon, 22 Feb 2016 13:21:13 +0100 Subject: [PATCH 2/3] Enable override default headers from CLI --- hyper/cli.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hyper/cli.py b/hyper/cli.py index 90f68f25..48ce7982 100644 --- a/hyper/cli.py +++ b/hyper/cli.py @@ -164,12 +164,14 @@ def set_request_data(args): body, headers, params = {}, {}, {} for i in args.items: if i.sep == SEP_HEADERS: - # :key:value case - if i.key == '': - k, v = i.value.split(':') - headers[':' + k] = v - else: + if i.key: headers[i.key] = i.value + else: + # when overriding a HTTP/2 special header there will be a leading + # colon, which tricks the command line parser into thinking + # the header is empty + k, v = i.value.split(':', 1) + headers[':' + k] = v elif i.sep == SEP_QUERY: params[i.key] = i.value elif i.sep == SEP_DATA: From e509c7a726eda44aa6f30923f11a7b788a65323a Mon Sep 17 00:00:00 2001 From: pkrolikowski Date: Mon, 22 Feb 2016 14:02:00 +0100 Subject: [PATCH 3/3] Enable override default headers from CLI --- hyper/cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hyper/cli.py b/hyper/cli.py index 48ce7982..7e862154 100644 --- a/hyper/cli.py +++ b/hyper/cli.py @@ -167,9 +167,9 @@ def set_request_data(args): if i.key: headers[i.key] = i.value else: - # when overriding a HTTP/2 special header there will be a leading - # colon, which tricks the command line parser into thinking - # the header is empty + # when overriding a HTTP/2 special header there will be a leading + # colon, which tricks the command line parser into thinking + # the header is empty k, v = i.value.split(':', 1) headers[':' + k] = v elif i.sep == SEP_QUERY: