--json with no data sets Content-Type as well

Closes #137
This commit is contained in:
Jakub Roztocil 2013-04-02 11:07:14 -03:00
parent 9b2a293e6e
commit 6e5c696ac9
2 changed files with 4 additions and 2 deletions

View File

@ -46,7 +46,7 @@ def get_requests_kwargs(args):
auto_json = args.data and not args.form auto_json = args.data and not args.form
if args.json or auto_json: if args.json or auto_json:
implicit_headers['Accept'] = 'application/json' implicit_headers['Accept'] = 'application/json'
if args.data: if args.json or (auto_json and args.data):
implicit_headers['Content-Type'] = JSON implicit_headers['Content-Type'] = JSON
if isinstance(args.data, dict): if isinstance(args.data, dict):

View File

@ -436,7 +436,9 @@ class AutoContentTypeAndAcceptHeadersTest(BaseTestCase):
) )
self.assertIn(OK, r) self.assertIn(OK, r)
self.assertEqual(r.json['headers']['Accept'], 'application/json') self.assertEqual(r.json['headers']['Accept'], 'application/json')
self.assertFalse(r.json['headers'].get('Content-Type')) # Make sure Content-Type gets set even with no data.
# https://github.com/jkbr/httpie/issues/137
self.assertIn('application/json', r.json['headers']['Content-Type'])
def test_GET_explicit_JSON_explicit_headers(self): def test_GET_explicit_JSON_explicit_headers(self):
r = http( r = http(