Merge pull request #173 from jackfischer/master

fix for cookie header capitalization bug
This commit is contained in:
Eli Uriegas 2016-12-03 17:28:38 -06:00 committed by GitHub
commit 80af9e6d76
2 changed files with 16 additions and 2 deletions

View File

@ -114,9 +114,10 @@ class Request(dict):
@property @property
def cookies(self): def cookies(self):
if self._cookies is None: if self._cookies is None:
if 'Cookie' in self.headers: cookie = self.headers.get('Cookie') or self.headers.get('cookie')
if cookie is not None:
cookies = SimpleCookie() cookies = SimpleCookie()
cookies.load(self.headers['Cookie']) cookies.load(cookie)
self._cookies = {name: cookie.value self._cookies = {name: cookie.value
for name, cookie in cookies.items()} for name, cookie in cookies.items()}
else: else:

View File

@ -25,6 +25,19 @@ def test_cookies():
assert response.text == 'Cookies are: working!' assert response.text == 'Cookies are: working!'
assert response_cookies['right_back'].value == 'at you' 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(): def test_cookie_options():
app = Sanic('test_text') app = Sanic('test_text')