Skip to content

Instantly share code, notes, and snippets.

@kdrakon
Created December 20, 2022 23:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdrakon/80f481d2b0f1cbb90bf05bdbe612fac4 to your computer and use it in GitHub Desktop.
Save kdrakon/80f481d2b0f1cbb90bf05bdbe612fac4 to your computer and use it in GitHub Desktop.
FastAPI wrapping cookies in quotes (`"..."`)?
# doing this...
cookie_name = "Some-Cookie"
cookie = "yum"
response.set_cookie(cookie_name, cookie)
# and getting a cookie wrapped in quotes that your browser or downstream server doesn't like?
# do this instead...
response.headers['set-cookie'] = f"{cookie_name}={cookie}; Path=/; Secure; HttpOnly"
# this will write the cookie as a raw header that the client/browser should treat better
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment