expression
Redirect response with Location
A redirect points to another reference. In 307 and 308 redirects the client must not change the method when following automatically; other redirect statuses have distinct semantics. Recheck destination policy and replayability at each redirect. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): 307 /new-path Common mistake: Automatically following every redirect while forwarding credentials without checking its destination.
Formal Syntax & Structure
rust syntaxrust
Response::builder().status(...).header(LOCATION, ...)Working Example
Example Snippetrust
fn main() { use http::{Response, StatusCode, header::LOCATION}; let r = Response::builder().status(StatusCode::TEMPORARY_REDIRECT).header(LOCATION, "/new-path").body(()).unwrap(); println!("{} {}", r.status().as_u16(), r.headers()[LOCATION].to_str().unwrap());}