You've already forked httpie-cli
							
							
				mirror of
				https://github.com/httpie/cli.git
				synced 2025-10-30 23:47:52 +02:00 
			
		
		
		
	Reintroduce $ https command alias with https:// as default scheme
				
					
				
			Close #608
This commit is contained in:
		| @@ -7,9 +7,6 @@ env: | |||||||
|   global: |   global: | ||||||
|     - NEWEST_PYTHON=3.7 |     - NEWEST_PYTHON=3.7 | ||||||
| python: | python: | ||||||
|   # Python 3.4 fails installing packages |  | ||||||
|   # <https://travis-ci.org/jakubroztocil/httpie/jobs/403263566#L636> |  | ||||||
|   # - 3.4 |  | ||||||
|   - 3.5 |   - 3.5 | ||||||
|   - 3.6 |   - 3.6 | ||||||
|   # - 3.7  # is done in the matrix below as described in travis-ci/travis-ci#9069 |   # - 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. | * Removed Python’s default limit of 100 response headers. | ||||||
| * Added ``--max-headers`` to allow setting the max header limit. | * Added ``--max-headers`` to allow setting the max header limit. | ||||||
| * Added ``--compress``. | * Added ``--compress``. | ||||||
|  | * Added ``https`` alias command with ``https://`` as the default scheme. | ||||||
|  |  | ||||||
|  |  | ||||||
| `1.0.3`_ (2019-08-26) | `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 | 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 | Unstable version | ||||||
| @@ -351,17 +351,33 @@ If the port is omitted, then port 80 is assumed. | |||||||
|     Host: localhost |     Host: localhost | ||||||
|  |  | ||||||
|  |  | ||||||
| Custom default scheme | Other default schemes | ||||||
| --------------------- | --------------------- | ||||||
|  |  | ||||||
| You can use the ``--default-scheme <URL_SCHEME>`` option to create | When HTTPie is invoked as ``https`` then the default scheme is ``https://`` | ||||||
| shortcuts for other protocols than HTTP: | (``$ 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 | .. 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 | Request items | ||||||
| ============= | ============= | ||||||
|  |  | ||||||
|   | |||||||
| @@ -168,7 +168,7 @@ def program(args, env, log_error): | |||||||
|             args.output_file.close() |             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. |     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) |     args = decode_args(args, env.stdin_encoding) | ||||||
|  |     program_name, *args = args | ||||||
|     plugin_manager.load_installed_plugins() |     plugin_manager.load_installed_plugins() | ||||||
|  |  | ||||||
|     def log_error(msg, *args, **kwargs): |     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 |     exit_status = ExitStatus.SUCCESS | ||||||
|  |  | ||||||
|     try: |     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: |     except KeyboardInterrupt: | ||||||
|         env.stderr.write('\n') |         env.stderr.write('\n') | ||||||
|         if include_traceback: |         if include_traceback: | ||||||
|   | |||||||
| @@ -132,13 +132,14 @@ class HTTPieArgumentParser(ArgumentParser): | |||||||
|     def __init__(self, *args, **kwargs): |     def __init__(self, *args, **kwargs): | ||||||
|         kwargs['add_help'] = False |         kwargs['add_help'] = False | ||||||
|         super(HTTPieArgumentParser, self).__init__(*args, **kwargs) |         super(HTTPieArgumentParser, self).__init__(*args, **kwargs) | ||||||
|  |         self.env = None | ||||||
|  |         self.args = None | ||||||
|  |  | ||||||
|     # noinspection PyMethodOverriding |     # 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.env = env | ||||||
|         self.args, no_options = super(HTTPieArgumentParser, self)\ |         self.args, no_options = super( | ||||||
|             .parse_known_args(args, namespace) |             HTTPieArgumentParser, self).parse_known_args(args, namespace) | ||||||
|  |  | ||||||
|         if self.args.debug: |         if self.args.debug: | ||||||
|             self.args.traceback = True |             self.args.traceback = True | ||||||
| @@ -154,7 +155,10 @@ class HTTPieArgumentParser(ArgumentParser): | |||||||
|         if not self.args.ignore_stdin and not env.stdin_isatty: |         if not self.args.ignore_stdin and not env.stdin_isatty: | ||||||
|             self._body_from_file(self.env.stdin) |             self._body_from_file(self.env.stdin) | ||||||
|         if not URL_SCHEME_RE.match(self.args.url): |         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) |             # See if we're using curl style shorthand for localhost (:3000/foo) | ||||||
|             shorthand = re.match(r'^:(?!:)(\d*)(/?.*)$', self.args.url) |             shorthand = re.match(r'^:(?!:)(\d*)(/?.*)$', self.args.url) | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								setup.py
									
									
									
									
									
								
							| @@ -82,6 +82,7 @@ setup( | |||||||
|     entry_points={ |     entry_points={ | ||||||
|         'console_scripts': [ |         'console_scripts': [ | ||||||
|             'http = httpie.__main__:main', |             'http = httpie.__main__:main', | ||||||
|  |             'https = httpie.__main__:main', | ||||||
|         ], |         ], | ||||||
|     }, |     }, | ||||||
|     extras_require=extras_require, |     extras_require=extras_require, | ||||||
| @@ -91,11 +92,6 @@ setup( | |||||||
|     classifiers=[ |     classifiers=[ | ||||||
|         'Development Status :: 5 - Production/Stable', |         'Development Status :: 5 - Production/Stable', | ||||||
|         'Programming Language :: Python', |         '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.5', | ||||||
|         'Programming Language :: Python :: 3.6', |         'Programming Language :: Python :: 3.6', | ||||||
|         'Programming Language :: Python :: 3.7', |         'Programming Language :: Python :: 3.7', | ||||||
|   | |||||||
| @@ -342,6 +342,10 @@ class TestSchemes: | |||||||
|         with pytest.raises(InvalidSchema): |         with pytest.raises(InvalidSchema): | ||||||
|             http('bah', '--default=scheme=foo+bar-BAZ.123') |             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) |         url = '{0}:{1}'.format(httpbin_secure.host, httpbin_secure.port) | ||||||
|         assert HTTP_OK in http(url, '--default-scheme=https') |         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 = ConnectionError('Connection aborted') | ||||||
|     exc.request = Request(method='GET', url='http://www.google.com') |     exc.request = Request(method='GET', url='http://www.google.com') | ||||||
|     get_response.side_effect = exc |     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 ret == ExitStatus.ERROR | ||||||
|     assert error_msg == ( |     assert error_msg == ( | ||||||
|         'ConnectionError: ' |         'ConnectionError: ' | ||||||
| @@ -34,7 +34,7 @@ def test_error_traceback(get_response): | |||||||
|     exc.request = Request(method='GET', url='http://www.google.com') |     exc.request = Request(method='GET', url='http://www.google.com') | ||||||
|     get_response.side_effect = exc |     get_response.side_effect = exc | ||||||
|     with raises(ConnectionError): |     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): | def test_max_headers_limit(httpbin_both): | ||||||
|   | |||||||
| @@ -140,7 +140,7 @@ class ExitStatusError(Exception): | |||||||
|     pass |     pass | ||||||
|  |  | ||||||
|  |  | ||||||
| def http(*args, **kwargs): | def http(*args, program_name='http', **kwargs): | ||||||
|     # noinspection PyUnresolvedReferences |     # noinspection PyUnresolvedReferences | ||||||
|     """ |     """ | ||||||
|     Run HTTPie and capture stderr/out and exit status. |     Run HTTPie and capture stderr/out and exit status. | ||||||
| @@ -197,7 +197,8 @@ def http(*args, **kwargs): | |||||||
|             add_to_args.append('--traceback') |             add_to_args.append('--traceback') | ||||||
|         if not any('--timeout' in arg for arg in args_with_config_defaults): |         if not any('--timeout' in arg for arg in args_with_config_defaults): | ||||||
|             add_to_args.append('--timeout=3') |             add_to_args.append('--timeout=3') | ||||||
|     args = add_to_args + args |  | ||||||
|  |     complete_args = [program_name, *add_to_args, *args] | ||||||
|  |  | ||||||
|     def dump_stderr(): |     def dump_stderr(): | ||||||
|         stderr.seek(0) |         stderr.seek(0) | ||||||
| @@ -205,7 +206,7 @@ def http(*args, **kwargs): | |||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         try: |         try: | ||||||
|             exit_status = main(args=args, **kwargs) |             exit_status = main(args=complete_args, **kwargs) | ||||||
|             if '--download' in args: |             if '--download' in args: | ||||||
|                 # Let the progress reporter thread finish. |                 # Let the progress reporter thread finish. | ||||||
|                 time.sleep(.5) |                 time.sleep(.5) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user