Added --default-scheme <URL_SCHEME>

Closes #289
This commit is contained in:
Jakub Roztocil 2016-07-02 12:47:02 +02:00
parent c3735d0422
commit 1124d68946
5 changed files with 19 additions and 4 deletions

View File

@ -14,6 +14,7 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
for macOS users (starting with HTTPie 0.9.4.).
* Added the ability to unset a request header with ``Header:``, and send an
empty value with ``Header;``.
* Added ``--default-scheme <URL_SCHEME>``.
`0.9.4`_ (2016-07-01)

View File

@ -313,6 +313,13 @@ this command:
GET /?search=HTTPie+logo&tbm=isch HTTP/1.1
You can use the ``--default-scheme <URL_SCHEME>`` option to create
shortcuts for other protocols than HTTP:
.. code-block:: bash
$ alias https="http --default-scheme https"
=============
Request Items

View File

@ -614,7 +614,6 @@ troubleshooting.add_argument(
)
troubleshooting.add_argument(
'--default-scheme',
choices=["http", "https"],
default="http",
help="""
Default scheme to use if not specified in the URL.

View File

@ -28,8 +28,6 @@ URL_SCHEME_RE = re.compile(r'^[a-z][a-z0-9.+-]*://', re.IGNORECASE)
HTTP_POST = 'POST'
HTTP_GET = 'GET'
HTTP = 'http://'
HTTPS = 'https://'
# Various separators used in args

View File

@ -330,8 +330,18 @@ class TestIgnoreStdin:
class TestSchemes:
def test_custom_scheme(self):
def test_invalid_custom_scheme(self):
# InvalidSchema is expected because HTTPie
# shouldn't touch a formally valid scheme.
with pytest.raises(InvalidSchema):
http('foo+bar-BAZ.123://bah')
def test_invalid_scheme_via_via_default_scheme(self):
# InvalidSchema is expected because HTTPie
# shouldn't touch a formally valid scheme.
with pytest.raises(InvalidSchema):
http('bah', '--default=scheme=foo+bar-BAZ.123')
def test_default_scheme(self, httpbin_secure):
url = '{0}:{1}'.format(httpbin_secure.host, httpbin_secure.port)
assert HTTP_OK in http(url, '--default-scheme=https')