Merge "Don't stream json"
This commit is contained in:
commit
e860a37ea8
@ -71,6 +71,10 @@ def get_details(method, orig_path, headers):
|
||||
'path': orig_path}
|
||||
|
||||
|
||||
def is_json_response(response):
|
||||
return response.headers.get('Content-Type') == 'application/json'
|
||||
|
||||
|
||||
def is_token_header_key(string):
|
||||
return string.lower() in ['x-auth-token', 'x-service-token']
|
||||
|
||||
@ -202,8 +206,9 @@ class RequestHandler(object):
|
||||
return resp
|
||||
|
||||
def _finalize(self, response):
|
||||
if self.stream:
|
||||
text = flask.stream_with_context(stream_response(response))
|
||||
if self.stream and not is_json_response(response):
|
||||
text = flask.stream_with_context(
|
||||
stream_response(response))
|
||||
else:
|
||||
text = response.text
|
||||
|
||||
@ -318,7 +323,7 @@ class RequestHandler(object):
|
||||
|
||||
@utils.CachedProperty
|
||||
def stream(self):
|
||||
return True if self.details['method'] in ['GET'] else False
|
||||
return self.details['method'] == 'GET'
|
||||
|
||||
@utils.CachedProperty
|
||||
def fallback_to_local(self):
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
import uuid
|
||||
import json
|
||||
import requests.models
|
||||
|
||||
from oslo_config import fixture as config_fixture
|
||||
|
||||
@ -134,3 +135,10 @@ class TestRequestHandler(BaseTest):
|
||||
'CONTENT-TYPE': 'application/json'})
|
||||
actual = json.loads(response.get_data(as_text=True))
|
||||
self.assertEqual(actual, {'images': []})
|
||||
|
||||
def test_is_json_response(self):
|
||||
response = requests.models.Response()
|
||||
response.headers['Content-Type'] = 'application/json'
|
||||
self.assertTrue(proxy.is_json_response(response))
|
||||
response.headers['Content-Type'] = 'application/text'
|
||||
self.assertFalse(proxy.is_json_response(response))
|
||||
|
Loading…
Reference in New Issue
Block a user