mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
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:
parent
76a92d4cde
commit
dcb3fb7382
2 changed files with 7 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue