How in the world can I get an header? #2551
-
I tried everything, but I'm too dumb to understand how request guards work. Yes, I have seen documentation and other GitHub Discussion posts. I still can't understand a bit. Please help me out! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Rocket provides a built-in guard for getting the IP Address, see here and here. This - under the hood - defaults to extracting the "X-Real-IP" header. #[get("/")]
async fn get_ip(ip: std::net::IpAddr) -> String {
format!("Your IP is: {}", ip)
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![get_ip])
} However, if you wish to manually extract a header, you have access to |
Beta Was this translation helpful? Give feedback.
Rocket provides a built-in guard for getting the IP Address, see here and here. This - under the hood - defaults to extracting the "X-Real-IP" header.
However, if you wish to manually extract a header, you have access to
.headers()
in a request guard (see here). I feel like this example is quite self-explanatory, and could be modified to your use-case quite easily by changing just the header names. If you have questions on that specifically, feel free to ask.