Merge pull request #347 from r0fls/345

false cookie attributes should not be set
This commit is contained in:
Eli Uriegas 2017-01-25 18:51:02 -06:00 committed by GitHub
commit 0f64702d72
2 changed files with 24 additions and 2 deletions

View File

@ -107,6 +107,7 @@ class Cookie(dict):
value.strftime("%a, %d-%b-%Y %T GMT")
))
elif key in self._flags:
if self[key]:
output.append(self._keys[key])
else:
output.append('%s=%s' % (self._keys[key], value))

View File

@ -3,6 +3,7 @@ from http.cookies import SimpleCookie
from sanic import Sanic
from sanic.response import json, text
from sanic.utils import sanic_endpoint_test
import pytest
# ------------------------------------------------------------ #
@ -25,6 +26,26 @@ def test_cookies():
assert response.text == 'Cookies are: working!'
assert response_cookies['right_back'].value == 'at you'
@pytest.mark.parametrize("httponly,expected", [
(False, False),
(True, True),
])
def test_false_cookies(httponly, expected):
app = Sanic('test_text')
@app.route('/')
def handler(request):
response = text('Cookies are: {}'.format(request.cookies['test']))
response.cookies['right_back'] = 'at you'
response.cookies['right_back']['httponly'] = httponly
return response
request, response = sanic_endpoint_test(app)
response_cookies = SimpleCookie()
response_cookies.load(response.headers.get('Set-Cookie', {}))
'HttpOnly' in response_cookies == expected
def test_http2_cookies():
app = Sanic('test_http2_cookies')