[invalid] Axum redirect::to().into_response() changing the http Status code (303 -> 307)

Trying to redirect a success/failure to a post into a redirect to a get, using Response::to which is documented to return a 303.

But when i into_response it, i see a 307, which then do not cause the browser to convert the origin POST into a GET.

Why is this happening? should't into_response preserve the redirect?

edit: i'm using into_response to normalize all my handlers to -> Response

It'd be much more useful if you post an MRE showing this behavior in order for people to help. Even if there is a genuine bug, you (or someone else) would have to report the bug to the maintainers which should hopefully contain an MRE showing this behavior; so it's a win-win.

Without seeing the actual code, here is a possible explanation.

1 Like

working on a minimal example... but i'm 99.999% sure that i'm doing something wrong, even tho it is just that call.

pub async fn get_session_html(
    Form(payload): Form<LoginPayload>,
) -> Response {
    match _login(payload.username, payload.password).await {
        Some(resp) => Html("<h1>ok</h1>").into_response(),
        //_ => StatusCode::UNAUTHORIZED.into_response(),
        _ => Redirect::to("/login.html?err").into_response(), // here i get 307 instead of 303
    }
}

we've worked around not using the into_response(), but still wanting to understand why that was happening

pub async fn get_session_html(
    Form(payload): Form<LoginPayload>,
) -> Result<Response, Redirect> {
    match _login(payload.username, payload.password).await {
        Some(resp) => Ok(Html("<h1>ok</h1>").into_response()),
        _ => Err(Redirect::to("/login.html?err")), // 303 just fine
    }
}

as expected it was user error somewhere. i could not reproduce with the minimum test case... and now using either methods described above it works as expected. git dissected the hell out of it and still cannot reproduce what we were seeing that day.