netloc_http_request/
lib.rs1#![warn(missing_docs)]
6
7use async_trait::async_trait;
8use netloc_core::reporter::{Data, Reporter};
9pub use reqwest::Client;
10
11pub struct HttpRequest {
13 pub client: Client,
15
16 pub url: String,
18}
19
20impl HttpRequest {
21 pub fn from_url(url: impl Into<String>) -> Self {
23 let client = Client::new();
24 let url = url.into();
25 Self { client, url }
26 }
27}
28
29#[async_trait]
30impl Reporter for HttpRequest {
31 type Error = Box<dyn std::error::Error>;
32
33 async fn report(&self, data: &Data) -> Result<(), Self::Error> {
34 self.client
35 .post(&self.url)
36 .header(reqwest::header::CONTENT_TYPE, "text/plain")
37 .body(data.ip.clone())
38 .send()
39 .await?;
40 Ok(())
41 }
42}