Response type hint should work with Response = Depends(...).
()
| 32 | |
| 33 | |
| 34 | def test_response_with_depends_default(): |
| 35 | """Response type hint should work with Response = Depends(...).""" |
| 36 | app = FastAPI() |
| 37 | |
| 38 | def modify_response(response: Response) -> Response: |
| 39 | response.headers["X-Custom"] = "modified" |
| 40 | return response |
| 41 | |
| 42 | @app.get("/") |
| 43 | def endpoint(response: Response = Depends(modify_response)): |
| 44 | return {"status": "ok"} |
| 45 | |
| 46 | client = TestClient(app) |
| 47 | resp = client.get("/") |
| 48 | |
| 49 | assert resp.status_code == 200 |
| 50 | assert resp.json() == {"status": "ok"} |
| 51 | assert resp.headers.get("X-Custom") == "modified" |
| 52 | |
| 53 | |
| 54 | def test_response_without_depends(): |