Compare commits
3 Commits
bare-cooki
...
response-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8027563144 | ||
|
|
875e921bda | ||
|
|
11c841ab4e |
@@ -73,16 +73,12 @@ def parse_cookie(raw: str) -> Dict[str, List[str]]:
|
||||
cookies: Dict[str, List[str]] = {}
|
||||
|
||||
for token in raw.split(";"):
|
||||
name, sep, value = token.partition("=")
|
||||
name, __, value = token.partition("=")
|
||||
name = name.strip()
|
||||
value = value.strip()
|
||||
|
||||
# Support cookies =value or plain value with no name
|
||||
# https://github.com/httpwg/http-extensions/issues/159
|
||||
if not sep:
|
||||
if not name:
|
||||
continue # Empty value like ;; or a cookie header with no value
|
||||
name, value = "", name
|
||||
if not name:
|
||||
continue
|
||||
|
||||
if COOKIE_NAME_RESERVED_CHARS.search(name): # no cov
|
||||
continue
|
||||
|
||||
@@ -24,7 +24,6 @@ from sanic.helpers import (
|
||||
Default,
|
||||
_default,
|
||||
has_message_body,
|
||||
remove_entity_headers,
|
||||
)
|
||||
from sanic.http import Http
|
||||
|
||||
@@ -106,9 +105,6 @@ class BaseHTTPResponse:
|
||||
Returns:
|
||||
Iterator[Tuple[bytes, bytes]]: A list of header tuples encoded in bytes for sending
|
||||
""" # noqa: E501
|
||||
# TODO: Make a blacklist set of header names and then filter with that
|
||||
if self.status in (304, 412): # Not Modified, Precondition Failed
|
||||
self.headers = remove_entity_headers(self.headers)
|
||||
if has_message_body(self.status):
|
||||
self.headers.setdefault("content-type", self.content_type)
|
||||
# Encode headers into bytes
|
||||
|
||||
@@ -11,20 +11,6 @@ from sanic.cookies.request import CookieRequestParameters
|
||||
from sanic.exceptions import ServerError
|
||||
from sanic.response import text
|
||||
from sanic.response.convenience import json
|
||||
from sanic.cookies.request import parse_cookie
|
||||
|
||||
def test_request_cookies():
|
||||
cdict = parse_cookie("foo=one; foo=two; abc = xyz;;bare;=bare2")
|
||||
assert cdict == {
|
||||
"foo": ["one", "two"],
|
||||
"abc": ["xyz"],
|
||||
"": ["bare", "bare2"],
|
||||
}
|
||||
c = CookieRequestParameters(cdict)
|
||||
assert c.getlist("foo") == ["one", "two"]
|
||||
assert c.getlist("abc") == ["xyz"]
|
||||
assert c.getlist("") == ["bare", "bare2"]
|
||||
assert c.getlist("bare") == None # [] might be sensible but we got None for now
|
||||
|
||||
|
||||
# ------------------------------------------------------------ #
|
||||
|
||||
@@ -178,6 +178,10 @@ def json_app(app):
|
||||
async def unmodified_handler(request: Request):
|
||||
return json(JSON_DATA, status=304)
|
||||
|
||||
@app.get("/precondition")
|
||||
async def precondition_handler(request: Request):
|
||||
return json(JSON_DATA, status=412)
|
||||
|
||||
@app.delete("/")
|
||||
async def delete_handler(request: Request):
|
||||
return json(None, status=204)
|
||||
@@ -193,6 +197,10 @@ def test_json_response(json_app):
|
||||
assert response.text == json_dumps(JSON_DATA)
|
||||
assert response.json == JSON_DATA
|
||||
|
||||
request, response = json_app.test_client.get("/precondition")
|
||||
assert response.status == 412
|
||||
assert response.json == JSON_DATA
|
||||
|
||||
|
||||
def test_no_content(json_app):
|
||||
request, response = json_app.test_client.get("/no-content")
|
||||
|
||||
Reference in New Issue
Block a user