Skip to content

Commit 97594ef

Browse files
committed
wip implementation of --base-url argument
Addresses #838
1 parent d262181 commit 97594ef

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

httpie/cli/argparser.py

+2
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def _process_request_type(self):
203203
}
204204

205205
def _process_url(self):
206+
self.args.url = self.args.base_url + self.args.url
207+
206208
if self.args.url.startswith('://'):
207209
# Paste URL & add space shortcut: `http ://pie.dev` → `http://pie.dev`
208210
self.args.url = self.args.url[3:]

httpie/cli/definition.py

+12
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
$ http :3000 # => http://localhost:3000
8282
$ http :/foo # => http://localhost/foo
8383
84+
Prefixed with --base-url before default scheme or shorthand processing take place.
85+
8486
""",
8587
)
8688
positional_arguments.add_argument(
@@ -713,6 +715,16 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False):
713715
action='store_true',
714716
short_help='Build the request and print it but don’t actually send it.'
715717
)
718+
network.add_argument(
719+
'--base-url',
720+
default='',
721+
short_help='String to prepend to the request URL.',
722+
help="""
723+
String to prepend to the request URL before --default-scheme and/or localhost
724+
shorthand are processed. If specified multiple times, last value is used.
725+
726+
"""
727+
)
716728
network.add_argument(
717729
'--proxy',
718730
default=[],

tests/test_cli.py

+5
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,8 @@ def test_default_scheme_option(self, httpbin_secure):
375375
def test_scheme_when_invoked_as_https(self, httpbin_secure):
376376
url = f'{httpbin_secure.host}:{httpbin_secure.port}'
377377
assert HTTP_OK in http(url, program_name='https')
378+
379+
380+
class TestBaseUrl:
381+
def test_base_url(self):
382+
assert False, 'Needs tests'

0 commit comments

Comments
 (0)