Skip to main content

foxtive_ntex/http/extractors/
client_info.rs

1use crate::error::HttpError;
2use crate::ext::request::RequestExt;
3use ntex::http::Payload;
4use ntex::web::{FromRequest, HttpRequest};
5
6pub struct ClientInfo {
7    pub ip: Option<String>,
8    pub ua: Option<String>,
9}
10
11impl ClientInfo {
12    pub fn into_parts(self) -> (Option<String>, Option<String>) {
13        (self.ip, self.ua)
14    }
15}
16
17impl<Err> FromRequest<Err> for ClientInfo {
18    type Error = HttpError;
19
20    async fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Result<Self, Self::Error> {
21        Ok(ClientInfo {
22            ip: req.ip(),
23            ua: req.user_agent(),
24        })
25    }
26}