You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-06-29 00:51:30 +02:00
Allow multiple fields with the same name.
Applies to form data and URL params: http -f url a=1 a=2 http url a==1 a==2
This commit is contained in:
@ -7,7 +7,7 @@ Many of the test cases here use httpbin.org.
|
||||
To make it run faster and offline you can::
|
||||
|
||||
# Install `httpbin` locally
|
||||
pip install httpbin
|
||||
pip install git+https://github.com/kennethreitz/httpbin.git
|
||||
|
||||
# Run it
|
||||
httpbin
|
||||
@ -15,6 +15,9 @@ To make it run faster and offline you can::
|
||||
# Run the tests against it
|
||||
HTTPBIN_URL=http://localhost:5000 python setup.py test
|
||||
|
||||
# Test all Python environments
|
||||
HTTPBIN_URL=http://localhost:5000 tox
|
||||
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
@ -55,11 +58,13 @@ def httpbin(path):
|
||||
class Response(str):
|
||||
"""
|
||||
A unicode subclass holding the output of `main()`, and also
|
||||
the exit status and contents of ``stderr``.
|
||||
the exit status, the contents of ``stderr``, and de-serialized
|
||||
JSON response (if possible).
|
||||
|
||||
"""
|
||||
exit_status = None
|
||||
stderr = None
|
||||
json = None
|
||||
|
||||
|
||||
def http(*args, **kwargs):
|
||||
@ -80,7 +85,7 @@ def http(*args, **kwargs):
|
||||
stdout = kwargs['env'].stdout = tempfile.TemporaryFile()
|
||||
stderr = kwargs['env'].stderr = tempfile.TemporaryFile()
|
||||
|
||||
exit_status = main(args=args, **kwargs)
|
||||
exit_status = main(args=['--traceback'] + list(args), **kwargs)
|
||||
|
||||
stdout.seek(0)
|
||||
stderr.seek(0)
|
||||
@ -92,6 +97,19 @@ def http(*args, **kwargs):
|
||||
stdout.close()
|
||||
stderr.close()
|
||||
|
||||
if TERMINAL_COLOR_PRESENCE_CHECK not in r:
|
||||
# De-serialize JSON body if possible.
|
||||
if r.strip().startswith('{'):
|
||||
r.json = json.loads(r)
|
||||
elif r.count('Content-Type:') == 1 and 'application/json' in r:
|
||||
try:
|
||||
j = r.strip()[r.strip().rindex('\n\n'):]
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
r.strip().index('\n')
|
||||
r.json = json.loads(j)
|
||||
|
||||
return r
|
||||
|
||||
|
||||
@ -157,6 +175,19 @@ class HTTPieTest(BaseTestCase):
|
||||
self.assertIn('HTTP/1.1 200', r)
|
||||
self.assertIn('"foo": "bar"', r)
|
||||
|
||||
def test_POST_form_multiple_values(self):
|
||||
r = http(
|
||||
'--form',
|
||||
'POST',
|
||||
httpbin('/post'),
|
||||
'foo=bar',
|
||||
'foo=baz',
|
||||
)
|
||||
self.assertIn('HTTP/1.1 200', r)
|
||||
self.assertDictEqual(r.json['form'], {
|
||||
'foo': ['bar', 'baz']
|
||||
})
|
||||
|
||||
def test_POST_stdin(self):
|
||||
|
||||
env = Environment(
|
||||
@ -490,8 +521,7 @@ class AuthTest(BaseTestCase):
|
||||
|
||||
def test_basic_auth(self):
|
||||
r = http(
|
||||
'--auth',
|
||||
'user:password',
|
||||
'--auth=user:password',
|
||||
'GET',
|
||||
httpbin('/basic-auth/user/password')
|
||||
)
|
||||
@ -502,8 +532,7 @@ class AuthTest(BaseTestCase):
|
||||
def test_digest_auth(self):
|
||||
r = http(
|
||||
'--auth-type=digest',
|
||||
'--auth',
|
||||
'user:password',
|
||||
'--auth=user:password',
|
||||
'GET',
|
||||
httpbin('/digest-auth/auth/user/password')
|
||||
)
|
||||
|
Reference in New Issue
Block a user