Skip to content

Commit

Permalink
wip implementation of --base-url argument
Browse files Browse the repository at this point in the history
Addresses httpie#838
  • Loading branch information
vergenzt committed Apr 27, 2022
1 parent d262181 commit 97594ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions httpie/cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
12 changes: 12 additions & 0 deletions httpie/cli/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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=[],
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 97594ef

Please sign in to comment.