Skip to content

Commit 3730925

Browse files
gnosyslambdaKludex
andauthored
Use removeprefix to strip weak ETag indicator in is_not_modified (#3193)
Signed-off-by: gnosyslambda <[email protected]> Co-authored-by: Marcelo Trylesinski <[email protected]>
1 parent e6f7ad1 commit 3730925

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎starlette/staticfiles.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def is_not_modified(self, response_headers: Headers, request_headers: Headers) -
210210
if if_none_match := request_headers.get("if-none-match"):
211211
# The "etag" header is added by FileResponse, so it's always present.
212212
etag = response_headers["etag"]
213-
return etag in [tag.strip(" W/") for tag in if_none_match.split(",")]
213+
return etag in [tag.strip().removeprefix("W/") for tag in if_none_match.split(",")]
214214

215215
try:
216216
if_modified_since = parsedate(request_headers["if-modified-since"])

‎tests/test_staticfiles.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ def test_staticfiles_304_with_etag_match(tmpdir: Path, test_client_factory: Test
214214
second_resp = client.get("/example.txt", headers={"if-none-match": f'W/{last_etag}, "123"'})
215215
assert second_resp.status_code == 304
216216
assert second_resp.content == b""
217+
second_resp = client.get("/example.txt", headers={"if-none-match": f'"123",\tW/{last_etag}'})
218+
assert second_resp.status_code == 304
219+
assert second_resp.content == b""
217220

218221

219222
def test_staticfiles_200_with_etag_mismatch(tmpdir: Path, test_client_factory: TestClientFactory) -> None:

0 commit comments

Comments
 (0)