From d86ac5e3e03f3a1469e9f4e1bce9af1919fbaa54 Mon Sep 17 00:00:00 2001 From: Jack Fischer Date: Sat, 26 Nov 2016 11:20:29 -0500 Subject: [PATCH 1/3] fix for cookie header capitalization bug --- sanic/request.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sanic/request.py b/sanic/request.py index 8023fd9c..676eaa51 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -114,6 +114,8 @@ class Request(dict): @property def cookies(self): if self._cookies is None: + if 'cookie' in self.headers: #HTTP2 cookie header + self.headers['Cookie'] = self.headers.pop('cookie') if 'Cookie' in self.headers: cookies = SimpleCookie() cookies.load(self.headers['Cookie']) From 0c215685f2e08ef4d5ff3b16d849194d81557133 Mon Sep 17 00:00:00 2001 From: Jack Fischer Date: Sun, 27 Nov 2016 08:30:46 -0500 Subject: [PATCH 2/3] refactoring cookies --- sanic/request.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 676eaa51..e5da4ce3 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -114,11 +114,10 @@ class Request(dict): @property def cookies(self): if self._cookies is None: - if 'cookie' in self.headers: #HTTP2 cookie header - self.headers['Cookie'] = self.headers.pop('cookie') - if 'Cookie' in self.headers: + cookie = self.headers.get('Cookie') or self.headers.get('cookie') + if cookie is not None: cookies = SimpleCookie() - cookies.load(self.headers['Cookie']) + cookies.load(cookie) self._cookies = {name: cookie.value for name, cookie in cookies.items()} else: From 9b466db5c9d1d717cfb136cacb741f59333445c3 Mon Sep 17 00:00:00 2001 From: Jack Fischer Date: Sat, 3 Dec 2016 15:19:24 -0500 Subject: [PATCH 3/3] test for http2 lowercase header cookies --- tests/test_cookies.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_cookies.py b/tests/test_cookies.py index 5b27c2e7..cf6a4259 100644 --- a/tests/test_cookies.py +++ b/tests/test_cookies.py @@ -25,6 +25,19 @@ def test_cookies(): assert response.text == 'Cookies are: working!' assert response_cookies['right_back'].value == 'at you' +def test_http2_cookies(): + app = Sanic('test_http2_cookies') + + @app.route('/') + async def handler(request): + response = text('Cookies are: {}'.format(request.cookies['test'])) + return response + + headers = {'cookie': 'test=working!'} + request, response = sanic_endpoint_test(app, headers=headers) + + assert response.text == 'Cookies are: working!' + def test_cookie_options(): app = Sanic('test_text')