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

Commit ac2ecd4

Browse files
committed
Merge pull request #169 from Lukasa/feature/h2-flag-cli
Add fallback to HTTP/2-only in plaintext from the CLI.
2 parents 8c4a13b + 7f2ef4b commit ac2ecd4

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist/
66
__pycache__
77
.coverage
88
.tox/
9+
.cache/

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ dev
1818
- Hyper CLI tool now correctly uses TLS for any ``https``-schemed URL.
1919
- Hyper CLI tool no longer attempts to decode bytes, instead writing them
2020
straight to the terminal.
21+
- Added new ``--h2`` flag to the Hyper CLI tool, which allows straight HTTP/2
22+
in plaintext, rather than attempting to upgrade from HTTP/1.1.
2123

2224
*Software Updates*
2325

hyper/cli.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pprint import pformat
1515
from textwrap import dedent
1616

17-
from hyper import HTTPConnection
17+
from hyper import HTTPConnection, HTTP20Connection
1818
from hyper import __version__
1919
from hyper.compat import is_py2, urlencode, urlsplit, write_to_stdout
2020

@@ -105,6 +105,9 @@ def make_troubleshooting_argument(parser):
105105
parser.add_argument(
106106
'--debug', action='store_true', default=False,
107107
help='Show debugging information (loglevel=DEBUG)')
108+
parser.add_argument(
109+
'--h2', action='store_true', default=False,
110+
help="Do HTTP/2 directly in plaintext: skip plaintext upgrade")
108111

109112

110113
def set_url_info(args):
@@ -218,7 +221,15 @@ def get_content_type_and_charset(response):
218221

219222

220223
def request(args):
221-
conn = HTTPConnection(args.url.host, args.url.port, secure=args.url.secure)
224+
if not args.h2:
225+
conn = HTTPConnection(
226+
args.url.host, args.url.port, secure=args.url.secure
227+
)
228+
else: # pragma: no cover
229+
conn = HTTP20Connection(
230+
args.url.host, args.url.port, secure=args.url.secure
231+
)
232+
222233
conn.request(args.method, args.url.path, args.body, args.headers)
223234
response = conn.get_response()
224235
log.debug('Response Headers:\n%s', pformat(response.headers))

0 commit comments

Comments
 (0)