You can declare a parameter in a path operation function or dependency to be of type
Response and then you can set data for the response like headers or cookies.
You can also use it directly to create an instance of it and return it from your path
operations.
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))