wip implementation of --base-url argument

Addresses httpie/httpie#838
This commit is contained in:
Tim Vergenz 2022-04-27 13:20:39 -04:00 committed by Tim Vergenz
parent 621042a048
commit e49b5132fa
3 changed files with 19 additions and 0 deletions

View File

@ -203,6 +203,8 @@ class HTTPieArgumentParser(BaseHTTPieArgumentParser):
}
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:]

View File

@ -78,6 +78,8 @@ positional_arguments.add_argument(
$ 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(
@ -703,6 +705,16 @@ network.add_argument(
action='store_true',
short_help='Build the request and print it but dont 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=[],

View File

@ -375,3 +375,8 @@ class TestSchemes:
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'