forked from extern/httpie-cli
Reintroduce $ https
command alias with https://
as default scheme
Close #608
This commit is contained in:
parent
8512a630f9
commit
8e04a24b90
@ -7,9 +7,6 @@ env:
|
||||
global:
|
||||
- NEWEST_PYTHON=3.7
|
||||
python:
|
||||
# Python 3.4 fails installing packages
|
||||
# <https://travis-ci.org/jakubroztocil/httpie/jobs/403263566#L636>
|
||||
# - 3.4
|
||||
- 3.5
|
||||
- 3.6
|
||||
# - 3.7 # is done in the matrix below as described in travis-ci/travis-ci#9069
|
||||
|
@ -13,6 +13,7 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
|
||||
* Removed Python’s default limit of 100 response headers.
|
||||
* Added ``--max-headers`` to allow setting the max header limit.
|
||||
* Added ``--compress``.
|
||||
* Added ``https`` alias command with ``https://`` as the default scheme.
|
||||
|
||||
|
||||
`1.0.3`_ (2019-08-26)
|
||||
|
26
README.rst
26
README.rst
@ -126,7 +126,7 @@ and always provides the latest version) is to use `pip`_:
|
||||
Python version
|
||||
--------------
|
||||
|
||||
Starting with version 2.0.0 (currently under development) Python 3.x is required.
|
||||
Starting with version 2.0.0 (currently under development) Python 3.5+ is required.
|
||||
|
||||
|
||||
Unstable version
|
||||
@ -351,17 +351,33 @@ If the port is omitted, then port 80 is assumed.
|
||||
Host: localhost
|
||||
|
||||
|
||||
Custom default scheme
|
||||
Other default schemes
|
||||
---------------------
|
||||
|
||||
You can use the ``--default-scheme <URL_SCHEME>`` option to create
|
||||
shortcuts for other protocols than HTTP:
|
||||
When HTTPie is invoked as ``https`` then the default scheme is ``https://``
|
||||
(``$ https example.org`` will make a request to ``https://example.org``).
|
||||
|
||||
You can also use the ``--default-scheme <URL_SCHEME>`` option to create
|
||||
shortcuts for other protocols than HTTP (possibly supported via plugins).
|
||||
Example for the `httpie-unixsocket <https://github.com/httpie/httpie-unixsocket>`_ plugin:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ alias https='http --default-scheme=https'
|
||||
# Before
|
||||
$ http http+unix://%2Fvar%2Frun%2Fdocker.sock/info
|
||||
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Create an alias
|
||||
$ alias http-unix='http --default-scheme="http+unix"'
|
||||
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Now the scheme can be omitted
|
||||
$ http-unix %2Fvar%2Frun%2Fdocker.sock/info
|
||||
|
||||
Request items
|
||||
=============
|
||||
|
||||
|
@ -168,7 +168,7 @@ def program(args, env, log_error):
|
||||
args.output_file.close()
|
||||
|
||||
|
||||
def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
|
||||
def main(args=sys.argv, env=Environment(), custom_log_error=None):
|
||||
"""
|
||||
The main function.
|
||||
|
||||
@ -179,6 +179,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
|
||||
|
||||
"""
|
||||
args = decode_args(args, env.stdin_encoding)
|
||||
program_name, *args = args
|
||||
plugin_manager.load_installed_plugins()
|
||||
|
||||
def log_error(msg, *args, **kwargs):
|
||||
@ -206,7 +207,11 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
|
||||
exit_status = ExitStatus.SUCCESS
|
||||
|
||||
try:
|
||||
parsed_args = parser.parse_args(args=args, env=env)
|
||||
parsed_args = parser.parse_args(
|
||||
args=args,
|
||||
program_name=program_name,
|
||||
env=env,
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
env.stderr.write('\n')
|
||||
if include_traceback:
|
||||
|
@ -132,13 +132,14 @@ class HTTPieArgumentParser(ArgumentParser):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['add_help'] = False
|
||||
super(HTTPieArgumentParser, self).__init__(*args, **kwargs)
|
||||
self.env = None
|
||||
self.args = None
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def parse_args(self, env, args=None, namespace=None):
|
||||
|
||||
def parse_args(self, env, program_name='http', args=None, namespace=None):
|
||||
self.env = env
|
||||
self.args, no_options = super(HTTPieArgumentParser, self)\
|
||||
.parse_known_args(args, namespace)
|
||||
self.args, no_options = super(
|
||||
HTTPieArgumentParser, self).parse_known_args(args, namespace)
|
||||
|
||||
if self.args.debug:
|
||||
self.args.traceback = True
|
||||
@ -154,7 +155,10 @@ class HTTPieArgumentParser(ArgumentParser):
|
||||
if not self.args.ignore_stdin and not env.stdin_isatty:
|
||||
self._body_from_file(self.env.stdin)
|
||||
if not URL_SCHEME_RE.match(self.args.url):
|
||||
scheme = self.args.default_scheme + "://"
|
||||
if os.path.basename(program_name) == 'https':
|
||||
scheme = 'https://'
|
||||
else:
|
||||
scheme = self.args.default_scheme + "://"
|
||||
|
||||
# See if we're using curl style shorthand for localhost (:3000/foo)
|
||||
shorthand = re.match(r'^:(?!:)(\d*)(/?.*)$', self.args.url)
|
||||
|
6
setup.py
6
setup.py
@ -82,6 +82,7 @@ setup(
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'http = httpie.__main__:main',
|
||||
'https = httpie.__main__:main',
|
||||
],
|
||||
},
|
||||
extras_require=extras_require,
|
||||
@ -91,11 +92,6 @@ setup(
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.1',
|
||||
'Programming Language :: Python :: 3.2',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Programming Language :: Python :: 3.7',
|
||||
|
@ -342,6 +342,10 @@ class TestSchemes:
|
||||
with pytest.raises(InvalidSchema):
|
||||
http('bah', '--default=scheme=foo+bar-BAZ.123')
|
||||
|
||||
def test_default_scheme(self, httpbin_secure):
|
||||
def test_default_scheme_option(self, httpbin_secure):
|
||||
url = '{0}:{1}'.format(httpbin_secure.host, httpbin_secure.port)
|
||||
assert HTTP_OK in http(url, '--default-scheme=https')
|
||||
|
||||
def test_scheme_when_invoked_as_https(self, httpbin_secure):
|
||||
url = '{0}:{1}'.format(httpbin_secure.host, httpbin_secure.port)
|
||||
assert HTTP_OK in http(url, program_name='https')
|
||||
|
@ -20,7 +20,7 @@ def test_error(get_response):
|
||||
exc = ConnectionError('Connection aborted')
|
||||
exc.request = Request(method='GET', url='http://www.google.com')
|
||||
get_response.side_effect = exc
|
||||
ret = main(['--ignore-stdin', 'www.google.com'], custom_log_error=error)
|
||||
ret = main(['http', '--ignore-stdin', 'www.google.com'], custom_log_error=error)
|
||||
assert ret == ExitStatus.ERROR
|
||||
assert error_msg == (
|
||||
'ConnectionError: '
|
||||
@ -34,7 +34,7 @@ def test_error_traceback(get_response):
|
||||
exc.request = Request(method='GET', url='http://www.google.com')
|
||||
get_response.side_effect = exc
|
||||
with raises(ConnectionError):
|
||||
main(['--ignore-stdin', '--traceback', 'www.google.com'])
|
||||
main(['http', '--ignore-stdin', '--traceback', 'www.google.com'])
|
||||
|
||||
|
||||
def test_max_headers_limit(httpbin_both):
|
||||
|
@ -140,7 +140,7 @@ class ExitStatusError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def http(*args, **kwargs):
|
||||
def http(*args, program_name='http', **kwargs):
|
||||
# noinspection PyUnresolvedReferences
|
||||
"""
|
||||
Run HTTPie and capture stderr/out and exit status.
|
||||
@ -197,7 +197,8 @@ def http(*args, **kwargs):
|
||||
add_to_args.append('--traceback')
|
||||
if not any('--timeout' in arg for arg in args_with_config_defaults):
|
||||
add_to_args.append('--timeout=3')
|
||||
args = add_to_args + args
|
||||
|
||||
complete_args = [program_name, *add_to_args, *args]
|
||||
|
||||
def dump_stderr():
|
||||
stderr.seek(0)
|
||||
@ -205,7 +206,7 @@ def http(*args, **kwargs):
|
||||
|
||||
try:
|
||||
try:
|
||||
exit_status = main(args=args, **kwargs)
|
||||
exit_status = main(args=complete_args, **kwargs)
|
||||
if '--download' in args:
|
||||
# Let the progress reporter thread finish.
|
||||
time.sleep(.5)
|
||||
|
Loading…
Reference in New Issue
Block a user