From 3842ef879298adaa8daf3bbb9899f4efffbb5451 Mon Sep 17 00:00:00 2001 From: Christopher Wolfe Date: Wed, 9 Jan 2019 15:32:21 -0500 Subject: [PATCH] Tests _http_resp_deserialize() with a response that lacks a Content-Type header. --- tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests.py b/tests.py index 2d2ddd8..6b88cab 100644 --- a/tests.py +++ b/tests.py @@ -1,3 +1,4 @@ +import io import json import logging import os @@ -413,3 +414,16 @@ class MixinTestCase(testing.AsyncHTTPTestCase): client = httpclient.AsyncHTTPClient() self.assertEqual(client.max_clients, 25) + @testing.gen_test() + def test_missing_content_type(self): + # Craft a response that lacks a Content-Type header. + request = httpclient.HTTPRequest( + self.get_url('/test?foo=bar&status_code=200')) + response = httpclient.HTTPResponse( + request, code=200, headers={}, + buffer=io.StringIO('Do not try to deserialize me.')) + # Try to deserialize that response. It should not raise an exception. + try: + response_body = self.mixin._http_resp_deserialize(response) + except KeyError: + self.fail('http_fetch raised KeyError!')