-j/--json now adds "Accept": "application/json" to GET requests if no previous Accept header exists.

This commit is contained in:
Jake Basile 2012-04-14 14:13:53 -05:00
parent 4da3821bc4
commit 45ce446017
2 changed files with 6 additions and 0 deletions

View File

@ -124,6 +124,8 @@ def main(args=None,
# JSON/Form content type.
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:
data = json.dumps(data)
if not files and ('Content-Type' not in headers and (data or args.json)):

View File

@ -94,6 +94,10 @@ class TestHTTPie(BaseTest):
def test_json(self):
response = http('POST', 'http://httpbin.org/post', 'foo=bar')
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):
response = http('--form', 'POST', 'http://httpbin.org/post', 'foo=bar')