Merge pull request #43 from jakebasile/master

-j/--json sets Accept header
This commit is contained in:
Jakub Roztocil 2012-04-14 14:21:08 -07:00
commit 6db93b25d8
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')