mirror of
https://github.com/sprockets/sprockets.mixins.http.git
synced 2024-11-14 19:29:31 +00:00
commit
b3b06e5f99
2 changed files with 20 additions and 0 deletions
|
@ -278,6 +278,8 @@ class HTTPClientMixin(object):
|
|||
"""
|
||||
if not response.body:
|
||||
return None
|
||||
if 'Content-Type' not in response.headers:
|
||||
return response.body
|
||||
try:
|
||||
content_type = algorithms.select_content_type(
|
||||
[headers.parse_content_type(response.headers['Content-Type'])],
|
||||
|
|
18
tests.py
18
tests.py
|
@ -1,6 +1,9 @@
|
|||
import io
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import uuid
|
||||
|
||||
from tornado import httpclient, httputil, testing, web
|
||||
|
@ -413,3 +416,18 @@ class MixinTestCase(testing.AsyncHTTPTestCase):
|
|||
client = httpclient.AsyncHTTPClient()
|
||||
self.assertEqual(client.max_clients, 25)
|
||||
|
||||
@testing.gen_test()
|
||||
@unittest.skipUnless(sys.version_info >= (3, ),
|
||||
'StringIO requires Python 3')
|
||||
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!')
|
||||
|
|
Loading…
Reference in a new issue