From ce0baf07c0484d7e65b1d93cdd1ec4a1f8fcd60a Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Sun, 24 Mar 2013 12:52:46 +0100 Subject: Allow request headers access in app context. - Give extensions access to request headers in app context. - Implements: blueprint allow-access-to-headers-for-extension. Change-Id: I22bba172a8ceaba9260487666172586c45aa95d4 --- .mailmap | 1 + keystone/common/wsgi.py | 3 ++- tests/test_wsgi.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index 737f9738..ae9016a8 100644 --- a/.mailmap +++ b/.mailmap @@ -21,3 +21,4 @@ Sirish Bitra sirish.bitra Sirish Bitra sirishbitra Sirish Bitra root Zhongyue Luo +Chmouel Boudjnah diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py index a07ae117..d5368b2a 100644 --- a/keystone/common/wsgi.py +++ b/keystone/common/wsgi.py @@ -161,9 +161,10 @@ class Application(BaseApplication): del arg_dict['controller'] LOG.debug(_('arg_dict: %s'), arg_dict) - # allow middleware up the stack to provide context & params + # allow middleware up the stack to provide context, params and headers. context = req.environ.get(CONTEXT_ENV, {}) context['query_string'] = dict(req.params.iteritems()) + context['headers'] = dict(req.headers.iteritems()) context['path'] = req.environ['PATH_INFO'] params = req.environ.get(PARAMS_ENV, {}) if 'REMOTE_USER' in req.environ: diff --git a/tests/test_wsgi.py b/tests/test_wsgi.py index 2d81ba86..0cd6a733 100644 --- a/tests/test_wsgi.py +++ b/tests/test_wsgi.py @@ -84,6 +84,17 @@ class ApplicationTest(BaseWSGITest): resp = req.get_response(FakeApp()) self.assertEqual(jsonutils.loads(resp.body), {'1': '2'}) + def test_headers_available(self): + class FakeApp(wsgi.Application): + def index(self, context): + return context['headers'] + + app = FakeApp() + req = self._make_request(url='/?1=2') + req.headers['X-Foo'] = "bar" + resp = req.get_response(app) + self.assertIn('X-Foo', eval(resp.body)) + def test_render_response(self): data = {'attribute': 'value'} body = '{"attribute": "value"}' -- cgit