mirror of
https://github.com/httpie/cli.git
synced 2025-02-03 13:01:58 +02:00
Issue #54 Method suggestion proposal
This commit is contained in:
parent
e06c448a75
commit
78fff98712
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -40,6 +41,12 @@ def _get_response(parser, args, stdin, stdin_isatty):
|
|||||||
# Form
|
# Form
|
||||||
args.headers['Content-Type'] = TYPE_FORM
|
args.headers['Content-Type'] = TYPE_FORM
|
||||||
|
|
||||||
|
if args.method is None and not args.items:
|
||||||
|
args.method = 'GET'
|
||||||
|
elif not re.match('^[a-zA-Z]+$', args.method):
|
||||||
|
args.items.insert(0, args.url)
|
||||||
|
args.method, args.url = 'POST', args.method
|
||||||
|
|
||||||
# Fire the request.
|
# Fire the request.
|
||||||
try:
|
try:
|
||||||
credentials = None
|
credentials = None
|
||||||
|
@ -171,6 +171,8 @@ parser.add_argument(
|
|||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'method', metavar='METHOD',
|
'method', metavar='METHOD',
|
||||||
|
nargs='?',
|
||||||
|
default=None,
|
||||||
help=_('''
|
help=_('''
|
||||||
The HTTP method to be used for the request
|
The HTTP method to be used for the request
|
||||||
(GET, POST, PUT, DELETE, PATCH, ...).
|
(GET, POST, PUT, DELETE, PATCH, ...).
|
||||||
|
@ -144,6 +144,12 @@ class TestHTTPie(BaseTest):
|
|||||||
self.assertIn('"User-Agent": "HTTPie', response)
|
self.assertIn('"User-Agent": "HTTPie', response)
|
||||||
self.assertIn('"Foo": "bar"', response)
|
self.assertIn('"Foo": "bar"', response)
|
||||||
|
|
||||||
|
def test_get_suggestion(self):
|
||||||
|
http('http://httpbin.org/get')
|
||||||
|
|
||||||
|
def test_post_suggestion(self):
|
||||||
|
http('http://httpbin.org/post', 'hello=world')
|
||||||
|
|
||||||
|
|
||||||
class TestPrettyFlag(BaseTest):
|
class TestPrettyFlag(BaseTest):
|
||||||
"""Test the --pretty / --ugly flag handling."""
|
"""Test the --pretty / --ugly flag handling."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user