Skip to content

Commit

Permalink
ETag fixes for aio-libs#5298
Browse files Browse the repository at this point in the history
  • Loading branch information
greshilov committed Mar 23, 2021
1 parent 1a4126a commit e331b56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,15 @@ async def _sendfile(
def _strong_etag_match(etag_value: str, etags: Tuple[ETag, ...]) -> bool:
if len(etags) == 1 and etags[0].value == ETAG_ANY:
return True
else:
return any(etag.value == etag_value for etag in etags if not etag.is_weak)
return any(etag.value == etag_value for etag in etags if not etag.is_weak)

async def _not_modified(
self, request: "BaseRequest", etag_value: str, last_modified: float
) -> Optional[AbstractStreamWriter]:
self.set_status(HTTPNotModified.status_code)
self._length_check = False
self.etag = etag_value # type: ignore
self.last_modified = last_modified # type: ignore
self.etag = etag_value # type: ignore[assignment]
self.last_modified = last_modified # type: ignore[assignment]
# Delete any Content-Length headers provided by user. HTTP 304
# should always have empty response body
return await super().prepare(request)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,14 @@ async def invalid_handler_1(request):


@pytest.mark.parametrize(
"header,header_attr",
["header", "header_attr"],
[
pytest.param("If-Match", "if_match"),
pytest.param("If-None-Match", "if_none_match"),
],
)
@pytest.mark.parametrize(
"header_val,expected",
["header_val", "expected"],
[
pytest.param(
'"67ab43", W/"54ed21", "7892,dd"',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def test_etag_any() -> None:
)
def test_etag_invalid_value_set(invalid_value) -> None:
resp = StreamResponse()
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="is not a valid etag"):
resp.etag = invalid_value


Expand Down

0 comments on commit e331b56

Please sign in to comment.