Skip to content
Discussion options

You must be logged in to vote

I’d generate the signed cookie via SignedCookieJar, convert it into a response, then take the Set-Cookie header and use the name=value part as the request Cookie header.

Something like:

use axum::{
    body::Body,
    http::{header, Request},
    response::IntoResponse,
};
use axum_extra::extract::cookie::{Cookie, Key, SignedCookieJar};
use tower::ServiceExt;

let key = Key::generate();
let session_id = "...";

let jar = SignedCookieJar::new(key.clone())
    .add(Cookie::new("sid", session_id.to_owned()));

let res = jar.into_response();

let cookie_header = res
    .headers()
    .get(header::SET_COOKIE)
    .unwrap()
    .to_str()
    .unwrap()
    .split(';')
    .next()
    .unwrap()

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PuercoPop
Comment options

Answer selected by PuercoPop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants