async def save_note(req): claims = await authenticator.get_auth_claims(req) location = "".join( random.choices(string.ascii_lowercase + string.digits, k=5)) security_key = str(uuid.uuid4()) file_name = str(uuid.uuid4()) await database.execute(note.insert(), values={ "file_name": file_name, "note_id": location, "security_key": security_key, "owner": -1 if claims is None else claims["userId"] }) original_note = await database.fetch_one( note.select().where(note.c.note_id == req.path_params["note"])) original_content = await storageBackend.get(original_note.file_name) await storageBackend.set(file_name, original_content) resp = PlainTextResponse(location) resp.set_cookie(f"{location}_securityKey", security_key) return resp
async def post(self, request: Request) -> Response: cookie = request.cookies.get(self._cookie_name, None) if not cookie: raise HTTPException(status_code=401, detail="The session cookie wasn't found.") await self._session_table.remove_session(token=cookie) if self._redirect_to is not None: response: Response = RedirectResponse( url=self._redirect_to, status_code=HTTP_303_SEE_OTHER) else: response = PlainTextResponse("Successfully logged out") response.set_cookie(self._cookie_name, "", max_age=0) return response
async def hi2(request): response = PlainTextResponse("ok") response.set_cookie("key", "value") response.set_cookie("key2", "value2") return response
async def app(scope: Scope, receive: Receive, send: Send) -> None: response = PlainTextResponse("Hello, world!") response.set_cookie("session_id", "1234") await response(scope, receive, send)