From 97594ef3ec52c477b7a254a3986149b869733221 Mon Sep 17 00:00:00 2001 From: Tim Vergenz Date: Wed, 27 Apr 2022 13:20:39 -0400 Subject: [PATCH] wip implementation of --base-url argument Addresses httpie/httpie#838 --- httpie/cli/argparser.py | 2 ++ httpie/cli/definition.py | 12 ++++++++++++ tests/test_cli.py | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/httpie/cli/argparser.py b/httpie/cli/argparser.py index e388e46533..a1c27d2419 100644 --- a/httpie/cli/argparser.py +++ b/httpie/cli/argparser.py @@ -203,6 +203,8 @@ def _process_request_type(self): } def _process_url(self): + self.args.url = self.args.base_url + self.args.url + if self.args.url.startswith('://'): # Paste URL & add space shortcut: `http ://pie.dev` → `http://pie.dev` self.args.url = self.args.url[3:] diff --git a/httpie/cli/definition.py b/httpie/cli/definition.py index 79e66f7f40..e3658a994c 100644 --- a/httpie/cli/definition.py +++ b/httpie/cli/definition.py @@ -81,6 +81,8 @@ $ http :3000 # => http://localhost:3000 $ http :/foo # => http://localhost/foo + Prefixed with --base-url before default scheme or shorthand processing take place. + """, ) positional_arguments.add_argument( @@ -713,6 +715,16 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): action='store_true', short_help='Build the request and print it but don’t actually send it.' ) +network.add_argument( + '--base-url', + default='', + short_help='String to prepend to the request URL.', + help=""" + String to prepend to the request URL before --default-scheme and/or localhost + shorthand are processed. If specified multiple times, last value is used. + + """ +) network.add_argument( '--proxy', default=[], diff --git a/tests/test_cli.py b/tests/test_cli.py index 6504c8a980..e9626d2757 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -375,3 +375,8 @@ def test_default_scheme_option(self, httpbin_secure): def test_scheme_when_invoked_as_https(self, httpbin_secure): url = f'{httpbin_secure.host}:{httpbin_secure.port}' assert HTTP_OK in http(url, program_name='https') + + +class TestBaseUrl: + def test_base_url(self): + assert False, 'Needs tests'