Skip to content

Commit c9c60fb

Browse files
committed
switch METHOD to option-only argument
1 parent 97594ef commit c9c60fb

File tree

2 files changed

+17
-46
lines changed

2 files changed

+17
-46
lines changed

httpie/cli/argparser.py

-28
Original file line numberDiff line numberDiff line change
@@ -414,39 +414,11 @@ def _guess_method(self):
414414
415415
"""
416416
if self.args.method is None:
417-
# Invoked as `http URL'.
418-
assert not self.args.request_items
419417
if self.has_input_data:
420418
self.args.method = HTTP_POST
421419
else:
422420
self.args.method = HTTP_GET
423421

424-
# FIXME: False positive, e.g., "localhost" matches but is a valid URL.
425-
elif not re.match('^[a-zA-Z]+$', self.args.method):
426-
# Invoked as `http URL item+'. The URL is now in `args.method`
427-
# and the first ITEM is now incorrectly in `args.url`.
428-
try:
429-
# Parse the URL as an ITEM and store it as the first ITEM arg.
430-
self.args.request_items.insert(0, KeyValueArgType(
431-
*SEPARATOR_GROUP_ALL_ITEMS).__call__(self.args.url))
432-
433-
except argparse.ArgumentTypeError as e:
434-
if self.args.traceback:
435-
raise
436-
self.error(e.args[0])
437-
438-
else:
439-
# Set the URL correctly
440-
self.args.url = self.args.method
441-
# Infer the method
442-
has_data = (
443-
self.has_input_data
444-
or any(
445-
item.sep in SEPARATOR_GROUP_DATA_ITEMS
446-
for item in self.args.request_items)
447-
)
448-
self.args.method = HTTP_POST if has_data else HTTP_GET
449-
450422
def _parse_items(self):
451423
"""
452424
Parse `args.request_items` into `args.headers`, `args.data`,

httpie/cli/definition.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,6 @@
5050
Only URL is required.
5151
""",
5252
)
53-
54-
positional_arguments.add_argument(
55-
dest='method',
56-
metavar='METHOD',
57-
nargs=Qualifiers.OPTIONAL,
58-
default=None,
59-
short_help='The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).',
60-
help="""
61-
The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).
62-
63-
This argument can be omitted in which case HTTPie will use POST if there
64-
is some data to be sent, otherwise GET:
65-
66-
$ http example.org # => GET
67-
$ http example.org hello=world # => POST
68-
69-
""",
70-
)
7153
positional_arguments.add_argument(
7254
dest='url',
7355
metavar='URL',
@@ -709,6 +691,23 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False):
709691

710692
network = options.add_group('Network')
711693

694+
network.add_argument(
695+
'--method',
696+
'-X',
697+
metavar='METHOD',
698+
default=None,
699+
short_help='The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).',
700+
help="""
701+
The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).
702+
703+
This argument can be omitted in which case HTTPie will use POST if there
704+
is some data to be sent, otherwise GET:
705+
706+
$ http example.org # => GET
707+
$ http example.org hello=world # => POST
708+
709+
""",
710+
)
712711
network.add_argument(
713712
'--offline',
714713
default=False,

0 commit comments

Comments
 (0)