mirror of https://github.com/encode/starlette.git
♻️ Do not use the deprecated `method` parameter in `FileResponse` inside of `StaticFiles` (#2406)
* ♻️ Do not use the deprecated `method` parameter in `FileResponse` inside of` StaticFile` * ✅ Add test for warning FileResponse with method argument * 🔊 Remove warning filter for FileResponse with method
This commit is contained in:
parent
1081520b75
commit
3734e85c18
|
@ -88,7 +88,6 @@ filterwarnings = [
|
|||
"ignore: The `allow_redirects` argument is deprecated. Use `follow_redirects` instead.:DeprecationWarning",
|
||||
"ignore: 'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning",
|
||||
"ignore: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.:RuntimeWarning",
|
||||
"ignore: The 'method' parameter is not used, and it will be removed.:DeprecationWarning:starlette",
|
||||
]
|
||||
|
||||
[tool.coverage.run]
|
||||
|
|
|
@ -184,11 +184,10 @@ class StaticFiles:
|
|||
scope: Scope,
|
||||
status_code: int = 200,
|
||||
) -> Response:
|
||||
method = scope["method"]
|
||||
request_headers = Headers(scope=scope)
|
||||
|
||||
response = FileResponse(
|
||||
full_path, status_code=status_code, stat_result=stat_result, method=method
|
||||
full_path, status_code=status_code, stat_result=stat_result
|
||||
)
|
||||
if self.is_not_modified(response.headers, request_headers):
|
||||
return NotModifiedResponse(response.headers)
|
||||
|
|
|
@ -324,6 +324,11 @@ def test_file_response_with_inline_disposition(tmpdir, test_client_factory):
|
|||
assert response.headers["content-disposition"] == expected_disposition
|
||||
|
||||
|
||||
def test_file_response_with_method_warns(tmpdir, test_client_factory):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
FileResponse(path=tmpdir, filename="example.png", method="GET")
|
||||
|
||||
|
||||
def test_set_cookie(test_client_factory, monkeypatch):
|
||||
# Mock time used as a reference for `Expires` by stdlib `SimpleCookie`.
|
||||
mocked_now = dt.datetime(2037, 1, 22, 12, 0, 0, tzinfo=dt.timezone.utc)
|
||||
|
|
Loading…
Reference in New Issue