Skip to content

Cannot specify Depends for type Response, yet docs imply you can? #9897

Answered by Kludex
holyoaks asked this question in Questions
Discussion options

You must be logged in to vote

This is a bug.

For the time being, you can do the following as a workaround:

from typing import Annotated
from fastapi import FastAPI, Response, Depends

app = FastAPI()

def set_no_cache_headers(response: Response) -> Response:
    response.headers["Potato"] = "potato"
    return response

@app.get("/")
def testing_response(response = Depends(set_no_cache_headers)):
    return {}

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@holyoaks
Comment options

@holyoaks
Comment options

@Kludex
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants