Add content-type to responses
* fixes bug 928055 Change-Id: Id86a9b3361d27493ed5ef175462aa1d4c1001bf4
This commit is contained in:
parent
3364905041
commit
6013dd83bb
|
@ -177,10 +177,13 @@ class Application(BaseApplication):
|
||||||
elif isinstance(result, webob.exc.WSGIHTTPException):
|
elif isinstance(result, webob.exc.WSGIHTTPException):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return self._serialize(result)
|
response = webob.Response()
|
||||||
|
self._serialize(response, result)
|
||||||
|
return response
|
||||||
|
|
||||||
def _serialize(self, result):
|
def _serialize(self, response, result):
|
||||||
return json.dumps(result, cls=utils.SmarterEncoder)
|
response.content_type = 'application/json'
|
||||||
|
response.body = json.dumps(result, cls=utils.SmarterEncoder)
|
||||||
|
|
||||||
def _normalize_arg(self, arg):
|
def _normalize_arg(self, arg):
|
||||||
return str(arg).replace(':', '_').replace('-', '_')
|
return str(arg).replace(':', '_').replace('-', '_')
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import webob
|
||||||
|
|
||||||
|
from keystone import test
|
||||||
|
from keystone.common import wsgi
|
||||||
|
|
||||||
|
|
||||||
|
class FakeApp(wsgi.Application):
|
||||||
|
def index(self, context):
|
||||||
|
return {'a': 'b'}
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationTest(test.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.app = FakeApp()
|
||||||
|
|
||||||
|
def _make_request(self):
|
||||||
|
req = webob.Request.blank('/')
|
||||||
|
args = {'action': 'index', 'controller': self.app}
|
||||||
|
req.environ['wsgiorg.routing_args'] = [None, args]
|
||||||
|
return req
|
||||||
|
|
||||||
|
def test_response_content_type(self):
|
||||||
|
req = self._make_request()
|
||||||
|
resp = req.get_response(self.app)
|
||||||
|
self.assertEqual(resp.content_type, 'application/json')
|
Loading…
Reference in New Issue