diff options
author | Prashanth Pai <ppai@redhat.com> | 2016-02-25 14:17:09 +0530 |
---|---|---|
committer | Thiago da Silva <thiago@redhat.com> | 2016-03-11 10:24:43 -0800 |
commit | 529526c68acb3acdf732d962b7cc8195081cbf56 (patch) | |
tree | 2ff66b835a010e230e0cdeac4e1f761f3ec7c15f /gluster | |
parent | 9d00e874b5b8f615ff7102639ccf375cc6630c94 (diff) |
Use correct content type on JSON responses
Currently, in cases where swauth returns a JSON document as its body,
it does not specify a content type, and swob defaults it to text/html.
This change uses a standard content type of 'application/json' in each
of these instances, and adjusts the tests accordingly.
This is ported from following commit in swauth repo:
556aa156979741292bde78425f413f9dee639b4f
Change-Id: Ib61370ba10b5e0364c2aed6321388715a6710355
Signed-off-by: Prashanth Pai <ppai@redhat.com>
Reviewed-on: http://review.gluster.org/13521
Reviewed-by: Thiago da Silva <thiago@redhat.com>
Tested-by: Thiago da Silva <thiago@redhat.com>
Diffstat (limited to 'gluster')
-rw-r--r-- | gluster/swift/common/middleware/gswauth/swauth/middleware.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/gluster/swift/common/middleware/gswauth/swauth/middleware.py b/gluster/swift/common/middleware/gswauth/swauth/middleware.py index cbcd95d..ccd85ca 100644 --- a/gluster/swift/common/middleware/gswauth/swauth/middleware.py +++ b/gluster/swift/common/middleware/gswauth/swauth/middleware.py @@ -43,6 +43,8 @@ import swift.common.wsgi from gluster.swift.common.middleware.gswauth.swauth import authtypes +CONTENT_TYPE_JSON = 'application/json' + class Swauth(object): """ @@ -589,7 +591,8 @@ class Swauth(object): if container['name'][0] != '.': listing.append({'name': container['name']}) marker = sublisting[-1]['name'].encode('utf-8') - return Response(body=json.dumps({'accounts': listing})) + return Response(body=json.dumps({'accounts': listing}), + content_type=CONTENT_TYPE_JSON) def handle_get_account(self, req): """ @@ -646,9 +649,10 @@ class Swauth(object): if obj['name'][0] != '.': listing.append({'name': obj['name']}) marker = sublisting[-1]['name'].encode('utf-8') - return Response(body=json.dumps( - {'account_id': account_id, - 'services': services, 'users': listing})) + return Response(content_type=CONTENT_TYPE_JSON, + body=json.dumps({'account_id': account_id, + 'services': services, + 'users': listing})) def handle_set_services(self, req): """ @@ -718,7 +722,8 @@ class Swauth(object): if resp.status_int // 100 != 2: raise Exception('Could not save .services object: %s %s' % (path, resp.status)) - return Response(request=req, body=services) + return Response(request=req, body=services, + content_type=CONTENT_TYPE_JSON) def handle_put_account(self, req): """ @@ -962,7 +967,7 @@ class Swauth(object): ('.reseller_admin' in display_groups and not self.is_super_admin(req)): return HTTPForbidden(request=req) - return Response(body=body) + return Response(body=body, content_type=CONTENT_TYPE_JSON) def handle_put_user(self, req): """ @@ -1208,6 +1213,7 @@ class Swauth(object): token = self.get_itoken(req.environ) url = '%s/%s' % (self.dsc_url, self.auth_account) return Response( + content_type=CONTENT_TYPE_JSON, request=req, body=json.dumps( {'storage': {'default': 'local', @@ -1315,6 +1321,7 @@ class Swauth(object): detail = json.loads(resp.body) url = detail['storage'][detail['storage']['default']] return Response( + content_type=CONTENT_TYPE_JSON, request=req, body=resp.body, headers={'x-auth-token': token, 'x-storage-token': token, 'x-auth-token-expires': str(int(expires - time())), |