forked from extern/httpie-cli
-j/--json now adds "Accept": "application/json" to GET requests if no previous Accept header exists.
This commit is contained in:
parent
4da3821bc4
commit
45ce446017
@ -124,6 +124,8 @@ def main(args=None,
|
|||||||
|
|
||||||
# JSON/Form content type.
|
# JSON/Form content type.
|
||||||
if args.json or (not args.form and data):
|
if args.json or (not args.form and data):
|
||||||
|
if args.method.lower() == 'get' and 'Accept' not in headers:
|
||||||
|
headers['Accept'] = 'application/json'
|
||||||
if stdin_isatty:
|
if stdin_isatty:
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
if not files and ('Content-Type' not in headers and (data or args.json)):
|
if not files and ('Content-Type' not in headers and (data or args.json)):
|
||||||
|
@ -94,6 +94,10 @@ class TestHTTPie(BaseTest):
|
|||||||
def test_json(self):
|
def test_json(self):
|
||||||
response = http('POST', 'http://httpbin.org/post', 'foo=bar')
|
response = http('POST', 'http://httpbin.org/post', 'foo=bar')
|
||||||
self.assertIn('"foo": "bar"', response)
|
self.assertIn('"foo": "bar"', response)
|
||||||
|
response2 = http('-j', 'GET', 'http://httpbin.org/headers')
|
||||||
|
self.assertIn('"Accept": "application/json"', response2)
|
||||||
|
response3 = http('-j', 'GET', 'http://httpbin.org/headers', 'Accept:application/xml')
|
||||||
|
self.assertIn('"Accept": "application/xml"', response3)
|
||||||
|
|
||||||
def test_form(self):
|
def test_form(self):
|
||||||
response = http('--form', 'POST', 'http://httpbin.org/post', 'foo=bar')
|
response = http('--form', 'POST', 'http://httpbin.org/post', 'foo=bar')
|
||||||
|
Loading…
Reference in New Issue
Block a user