How to set cookie in response? #351
Answered
by
davidpdrsn
goldwind-ting
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
davidpdrsn
Sep 28, 2021
Replies: 1 comment 4 replies
-
There are many ways to add headers to a response. See here for examples. The easiest way is to use use axum::{
http::header::SET_COOKIE,
response::{Headers, Html, IntoResponse},
};
async fn handler() -> impl IntoResponse {
let headers = Headers([(SET_COOKIE, "key=value")]);
let content = Html("<h1>Hello, World!</h1>");
(headers, content)
} |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
davidpdrsn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are many ways to add headers to a response. See here for examples.
The easiest way is to use
axum::response::Headers
: