During testing, ensure we're not getting text/html unexpectedly.

This commit is contained in:
Itamar Turner-Trauring 2023-05-01 11:41:51 -04:00
parent 6d961eada9
commit 5f19605075

View File

@ -443,11 +443,20 @@ class StorageClient(object):
kwargs["data"] = dumps(message_to_serialize)
headers.addRawHeader("Content-Type", CBOR_MIME_TYPE)
return await self._treq.request(
response = await self._treq.request(
method, url, headers=headers, timeout=timeout, **kwargs
)
async def decode_cbor(self, response, schema: Schema) -> object:
if self.TEST_MODE_REGISTER_HTTP_POOL is not None:
if response.code != 404:
# We're doing API queries, HTML is never correct except in 404, but
# it's the default for Twisted's web server so make sure nothing
# unexpected happened.
assert get_content_type(response.headers) != "text/html"
return response
async def decode_cbor(self, response: IResponse, schema: Schema) -> object:
"""Given HTTP response, return decoded CBOR body."""
with start_action(action_type="allmydata:storage:http-client:decode-cbor"):
if response.code > 199 and response.code < 300: