save the cookies

This commit is contained in:
bearllm 2022-09-11 19:37:17 +08:00 committed by GitHub
parent 6620273083
commit 1a0cf7f0bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,4 @@
from fastapi import Cookie, Depends, FastAPI
from fastapi import Cookie, Depends, FastAPI, Response
app = FastAPI()
@ -8,10 +8,12 @@ def query_extractor(q: str | None = None):
def query_or_cookie_extractor(
q: str = Depends(query_extractor), last_query: str | None = Cookie(default=None)
response: Response, q: str = Depends(query_extractor), last_query: str | None = Cookie(default=None)
):
if not q:
return last_query
else:
response.set_cookie(key="last_query", value=q)
return q