From 6e5c696ac9806386b81c2b5d3e65a3f65f66572d Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Tue, 2 Apr 2013 11:07:14 -0300 Subject: [PATCH] --json with no data sets Content-Type as well Closes #137 --- httpie/client.py | 2 +- tests/tests.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/httpie/client.py b/httpie/client.py index 1c73c5fe..e0d84e94 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -46,7 +46,7 @@ def get_requests_kwargs(args): auto_json = args.data and not args.form if args.json or auto_json: implicit_headers['Accept'] = 'application/json' - if args.data: + if args.json or (auto_json and args.data): implicit_headers['Content-Type'] = JSON if isinstance(args.data, dict): diff --git a/tests/tests.py b/tests/tests.py index 632d4195..0b1b9939 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -436,7 +436,9 @@ class AutoContentTypeAndAcceptHeadersTest(BaseTestCase): ) self.assertIn(OK, r) 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): r = http(