diff --git a/httpie/cli/argparser.py b/httpie/cli/argparser.py index 9bf09b3b73..30653a2b75 100644 --- a/httpie/cli/argparser.py +++ b/httpie/cli/argparser.py @@ -157,6 +157,20 @@ def parse_args( self.env = env self.env.args = namespace = namespace or argparse.Namespace() self.args, no_options = super().parse_known_args(args, namespace) + if self.args.url: + request_items = [ + option for option in no_options if not option.startswith('-') + ] + if request_items: + request_item_type = KeyValueArgType(*SEPARATOR_GROUP_ALL_ITEMS) + self.args.request_items = [ + *(self.args.request_items or []), + *(request_item_type(item) for item in request_items), + ] + no_options = [ + option for option in no_options + if option.startswith('-') + ] if self.args.debug: self.args.traceback = True self.has_stdin_data = ( diff --git a/tests/test_cli.py b/tests/test_cli.py index 2cd27574af..34e11bb404 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -149,6 +149,23 @@ def test_multiple_text_fields_with_same_field_name(self): ] +class TestIntermixedOptions: + def test_output_option_after_url_keeps_request_items(self): + r = http( + '--offline', + '--ignore-stdin', + 'post', + 'pie.dev/post', + '-v', + 'header1:xyz', + 'x=1', + ) + + assert r.exit_status == ExitStatus.SUCCESS + assert 'header1: xyz' in r + assert '"x": "1"' in r + + class TestQuerystring: def test_query_string_params_in_url(self, httpbin): r = http('--print=Hhb', 'GET', httpbin + '/get?a=1&b=2')