Response dependency should work in a chain of dependencies.
()
| 69 | |
| 70 | |
| 71 | def test_response_dependency_chain(): |
| 72 | """Response dependency should work in a chain of dependencies.""" |
| 73 | app = FastAPI() |
| 74 | |
| 75 | def first_modifier(response: Response) -> Response: |
| 76 | response.headers["X-First"] = "1" |
| 77 | return response |
| 78 | |
| 79 | def second_modifier( |
| 80 | response: Annotated[Response, Depends(first_modifier)], |
| 81 | ) -> Response: |
| 82 | response.headers["X-Second"] = "2" |
| 83 | return response |
| 84 | |
| 85 | @app.get("/") |
| 86 | def endpoint(response: Annotated[Response, Depends(second_modifier)]): |
| 87 | return {"status": "ok"} |
| 88 | |
| 89 | client = TestClient(app) |
| 90 | resp = client.get("/") |
| 91 | |
| 92 | assert resp.status_code == 200 |
| 93 | assert resp.headers.get("X-First") == "1" |
| 94 | assert resp.headers.get("X-Second") == "2" |
| 95 | |
| 96 | |
| 97 | def test_response_dependency_returns_different_response_instance(): |