Merge "Don't stream json"

This commit is contained in:
Jenkins 2017-08-02 20:42:08 +00:00 committed by Gerrit Code Review
commit e860a37ea8
2 changed files with 16 additions and 3 deletions

View File

@ -71,6 +71,10 @@ def get_details(method, orig_path, headers):
'path': orig_path} 'path': orig_path}
def is_json_response(response):
return response.headers.get('Content-Type') == 'application/json'
def is_token_header_key(string): def is_token_header_key(string):
return string.lower() in ['x-auth-token', 'x-service-token'] return string.lower() in ['x-auth-token', 'x-service-token']
@ -202,8 +206,9 @@ class RequestHandler(object):
return resp return resp
def _finalize(self, response): def _finalize(self, response):
if self.stream: if self.stream and not is_json_response(response):
text = flask.stream_with_context(stream_response(response)) text = flask.stream_with_context(
stream_response(response))
else: else:
text = response.text text = response.text
@ -318,7 +323,7 @@ class RequestHandler(object):
@utils.CachedProperty @utils.CachedProperty
def stream(self): def stream(self):
return True if self.details['method'] in ['GET'] else False return self.details['method'] == 'GET'
@utils.CachedProperty @utils.CachedProperty
def fallback_to_local(self): def fallback_to_local(self):

View File

@ -14,6 +14,7 @@
import uuid import uuid
import json import json
import requests.models
from oslo_config import fixture as config_fixture from oslo_config import fixture as config_fixture
@ -134,3 +135,10 @@ class TestRequestHandler(BaseTest):
'CONTENT-TYPE': 'application/json'}) 'CONTENT-TYPE': 'application/json'})
actual = json.loads(response.get_data(as_text=True)) actual = json.loads(response.get_data(as_text=True))
self.assertEqual(actual, {'images': []}) 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))