Use correct Content-Types in headers. (#3566)

* Add Content-Type: app/jose+json to post requests.

* Add tests for proper content type.
This commit is contained in:
Blake Griffith 2016-10-05 12:28:38 -07:00 committed by Peter Eckersley
parent 76a92d4cde
commit dcb3fb7382
2 changed files with 7 additions and 1 deletions

View file

@ -495,6 +495,7 @@ class Client(object): # pylint: disable=too-many-instance-attributes
class ClientNetwork(object): # pylint: disable=too-many-instance-attributes
"""Client network."""
JSON_CONTENT_TYPE = 'application/json'
JOSE_CONTENT_TYPE = 'application/jose+json'
JSON_ERROR_CONTENT_TYPE = 'application/problem+json'
REPLAY_NONCE_HEADER = 'Replay-Nonce'
@ -641,9 +642,10 @@ class ClientNetwork(object): # pylint: disable=too-many-instance-attributes
self._add_nonce(self.head(url))
return self._nonces.pop()
def post(self, url, obj, content_type=JSON_CONTENT_TYPE, **kwargs):
def post(self, url, obj, content_type=JOSE_CONTENT_TYPE, **kwargs):
"""POST object wrapped in `.JWS` and check response."""
data = self._wrap_in_jws(obj, self._get_nonce(url))
kwargs.setdefault('headers', {'Content-Type': content_type})
response = self._send_request('POST', url, data=data, **kwargs)
self._add_nonce(response)
return self._check_response(response, content_type=content_type)

View file

@ -630,6 +630,10 @@ class ClientNetworkWithMockedResponseTest(unittest.TestCase):
self.send_request.assert_called_once_with(
'GET', 'http://example.com/', bar='baz')
def test_post_no_content_type(self):
self.content_type = self.net.JOSE_CONTENT_TYPE
self.assertEqual(self.checked_response, self.net.post('uri', self.obj))
def test_post(self):
# pylint: disable=protected-access
self.assertEqual(self.checked_response, self.net.post(