aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2023-03-27 18:47:15 +0100
committerTomasz Kramkowski <tomasz@kramkow.ski>2023-03-27 19:01:34 +0100
commit4ad81ff7b008cb5defbf2a4d2d6012b8a597773c (patch)
tree0a07ae1971a06a1a1839ad55e9344067a22724c6
parent35534d46bef472b1d1cb19ee4c5949823053da2a (diff)
downloadpaste-4ad81ff7b008cb5defbf2a4d2d6012b8a597773c.tar.gz
paste-4ad81ff7b008cb5defbf2a4d2d6012b8a597773c.tar.xz
paste-4ad81ff7b008cb5defbf2a4d2d6012b8a597773c.zip
if_none_match: quote ETag values
-rw-r--r--paste/__init__.py4
-rw-r--r--tests/middleware/test_if_none_match.py3
2 files changed, 5 insertions, 2 deletions
diff --git a/paste/__init__.py b/paste/__init__.py
index c769997..1948273 100644
--- a/paste/__init__.py
+++ b/paste/__init__.py
@@ -141,7 +141,7 @@ def if_none_match(app: App, environ: Env, start_response: StartResponse) -> Resp
return app(environ, start_response)
if if_none_match == "*":
- start_response("304 Not Modified", [("ETag", etag)])
+ start_response("304 Not Modified", [("ETag", f'"{etag}"')])
return []
etags = if_none_match.split(",")
@@ -151,7 +151,7 @@ def if_none_match(app: App, environ: Env, start_response: StartResponse) -> Resp
return simple_response(start_response, "400 Bad Request")
etags = {e[1:-1] for e in etags}
if isinstance(etag, str) and etag in etags:
- start_response("304 Not Modified", [("ETag", etag)])
+ start_response("304 Not Modified", [("ETag", f'"{etag}"')])
return []
return app(environ, start_response)
diff --git a/tests/middleware/test_if_none_match.py b/tests/middleware/test_if_none_match.py
index 0a0cdf8..33d0d3b 100644
--- a/tests/middleware/test_if_none_match.py
+++ b/tests/middleware/test_if_none_match.py
@@ -56,6 +56,7 @@ def test_etag_matches_if_none_match_header(app, value):
response = call_app(app, environ)
assert response.data == b""
assert response.status == "304 Not Modified"
+ assert ("ETag", f'"{ETAG}"') in response.headers
@pytest.mark.parametrize(
@@ -74,6 +75,7 @@ def test_etag_matches_if_none_match_header_list(app, value):
response = call_app(app, environ)
assert response.data == b""
assert response.status == "304 Not Modified"
+ assert ("ETag", f'"{ETAG}"') in response.headers
def test_etag_matches_if_none_match_header_star(app):
@@ -81,6 +83,7 @@ def test_etag_matches_if_none_match_header_star(app):
response = call_app(app, environ)
assert response.data == b""
assert response.status == "304 Not Modified"
+ assert ("ETag", f'"{ETAG}"') in response.headers
def test_missing_etag_does_not_match_if_none_match_header_star():