Skip to content

Commit e49b513

Browse files
committed
wip implementation of --base-url argument
Addresses httpie#838
1 parent 621042a commit e49b513

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
@@ -78,6 +78,8 @@
7878
$ http :3000 # => http://localhost:3000
7979
$ http :/foo # => http://localhost/foo
8080
81+
Prefixed with --base-url before default scheme or shorthand processing take place.
82+
8183
""",
8284
)
8385
positional_arguments.add_argument(
@@ -703,6 +705,16 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False):
703705
action='store_true',
704706
short_help='Build the request and print it but don’t actually send it.'
705707
)
708+
network.add_argument(
709+
'--base-url',
710+
default='',
711+
short_help='String to prepend to the request URL.',
712+
help="""
713+
String to prepend to the request URL before --default-scheme and/or localhost
714+
shorthand are processed. If specified multiple times, last value is used.
715+
716+
"""
717+
)
706718
network.add_argument(
707719
'--proxy',
708720
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)