Skip to content

Commit

Permalink
♻️ Do not use the deprecated method parameter in FileResponse ins…
Browse files Browse the repository at this point in the history
…ide 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
  • Loading branch information
tiangolo committed Jan 11, 2024
1 parent 1081520 commit 3734e85
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions starlette/staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,10 @@ def file_response(
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)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3734e85

Please sign in to comment.