diff --git a/Cargo.lock b/Cargo.lock index 59d48f3..7eecab7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -889,6 +889,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.101" @@ -929,6 +938,35 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.3", +] + [[package]] name = "redox_syscall" version = "0.5.17" @@ -1437,9 +1475,12 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" name = "ubw-sward" version = "0.1.0" dependencies = [ + "bytes", + "rand", "reqwest", "tokio", "tower", + "url", ] [[package]] @@ -1755,6 +1796,26 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zerocopy" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zerofrom" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 7504107..f331cb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,6 @@ serde = { version = "1", features = ["derive"] } rand = "0.9" thiserror = "2.0" anyhow = "1.0" -url = "2.5" \ No newline at end of file +url = "2.5" +time = "0.3" +bytes = "1.10" \ No newline at end of file diff --git a/ubw-sward/Cargo.toml b/ubw-sward/Cargo.toml index 5129d9a..60f81de 100644 --- a/ubw-sward/Cargo.toml +++ b/ubw-sward/Cargo.toml @@ -6,4 +6,7 @@ edition = "2024" [dependencies] tokio = { workspace = true } tower = { workspace = true } -reqwest = {workspace = true} \ No newline at end of file +reqwest = {workspace = true} +url = {workspace = true} +rand = {workspace = true} +bytes = {workspace = true} \ No newline at end of file diff --git a/ubw-sward/src/http.rs b/ubw-sward/src/http.rs new file mode 100644 index 0000000..5601062 --- /dev/null +++ b/ubw-sward/src/http.rs @@ -0,0 +1,53 @@ +use bytes::Bytes; +use reqwest::header::HeaderMap; +use reqwest::{Client, Method}; +use std::pin::Pin; +use std::task::{Context, Poll}; +use tower::Service; +use url::Url; + +#[derive(Clone)] +pub struct SimpleHttpSward { + client: Client, + method: Method, + headers: HeaderMap, + sent_count: usize, +} + +impl SimpleHttpSward { + pub fn new(client: Client, method: Method, headers: HeaderMap) -> Self { + Self { + client, + method, + headers, + sent_count: 0, + } + } + pub fn sent_count(&self) -> usize { + self.sent_count + } +} + +#[derive(Clone)] +pub struct SimpleHttpRequest { + pub body: Option, + pub url: Url, +} + +impl Service for SimpleHttpSward { + type Response = reqwest::Response; + type Error = reqwest::Error; + type Future = Pin>>>; + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: SimpleHttpRequest) -> Self::Future { + self.sent_count += 1; + Box::pin( + self.client + .request(self.method.clone(), req.url) + .headers(self.headers.clone()) + .send(), + ) + } +} diff --git a/ubw-sward/src/lib.rs b/ubw-sward/src/lib.rs index e69de29..e05256f 100644 --- a/ubw-sward/src/lib.rs +++ b/ubw-sward/src/lib.rs @@ -0,0 +1 @@ +pub mod http; \ No newline at end of file