I have a POST endpoint:
use rocket::serde::json::Json;
use rocket::{ State, Request };
#[post(
"/my_endpoint",
format = "json",
data = "<json_my_data>"
)]
pub async fn my_endpoint(
request: &Request<'_>,
peer_state: &State<Arc<peers::MyPeer>>,
json_my_data: Json<models::JsonMyData>,
)
I want to get the IP address of the endpoint's caller. I was planning to use Rocket's Request:
let ip_address = match request.client_ip() {
Some(ip) => ip.to_string(),
None => {
error!("Invalid IP Address");
return;
},
};
But I get the following compilation error:
the trait bound `&rocket::Request<'_>: FromRequest<'_>` is not satisfied
I'm using the following Rocket version in my Cargo.toml
:
rocket = { git = "https://github.com/LIT-Protocol/Rocket", branch = "feature/port-reuse", features = ["json"] }
Is there a way to get the IP address of the caller without manually implementing the FromRequest
for the request
param?