]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
♻️ Do not use the deprecated `method` parameter in `FileResponse` inside of `StaticFi...
authorSebastián Ramírez <tiangolo@gmail.com>
Thu, 11 Jan 2024 15:17:18 +0000 (19:17 +0400)
committerGitHub <noreply@github.com>
Thu, 11 Jan 2024 15:17:18 +0000 (08:17 -0700)
* ♻️ 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

pyproject.toml
starlette/staticfiles.py
tests/test_responses.py

index 6e7e4e12bcd0b67d3c126bb050e4fe7d44467ecf..9909fb86a4237ebfd9e4468d26c687e42aa9916b 100644 (file)
@@ -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]
index 0101b11bc36334ce66f0108b4be482540f44711c..52614400be73ec438e4158c14a6f7fd6244d819d 100644 (file)
@@ -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)
index 6b6d07970c8fd754241c053268f3925696e9ee9b..6bccd23f2f1662ec748fca8137c4db54e336cc0d 100644 (file)
@@ -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)