diff --git a/Cargo.toml b/Cargo.toml index 5d6a995..b6feaed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,11 +6,12 @@ name = "xml-rpc" readme = "README.md" repository = "https://github.com/adnanademovic/xml-rpc-rs" version = "0.1.0" +edition = "2024" [dependencies] base64 = "0.22.1" error-chain = "0.12.4" -hyper = "0.10.15" +reqwest = { version = "0.12", features = ["blocking"] } lazy_static = "1.5.0" regex = "1.11.1" serde = { version = "1.0.217", features = ["derive"] } diff --git a/src/bin/echo.rs b/src/bin/echo.rs index 7c65151..ce45cba 100644 --- a/src/bin/echo.rs +++ b/src/bin/echo.rs @@ -39,7 +39,7 @@ pub fn main() { bar: "baz".into(), }; println!("Sending: {:?}", req); - let uri = "http://localhost:8080/".parse().unwrap(); + let uri = "http://localhost:8080/"; let res: Result, _> = client.call(&uri, "echo", req.clone()); println!("Echo Received: {:?}", res); let res: Result, _> = client.call(&uri, "double", req.clone()); diff --git a/src/bin/threadcheck.rs b/src/bin/threadcheck.rs index ba1628b..05169b2 100644 --- a/src/bin/threadcheck.rs +++ b/src/bin/threadcheck.rs @@ -32,25 +32,25 @@ fn main() { std::thread::sleep(Duration::from_secs(1)); let t1 = std::thread::spawn(|| { - call::<_, _, ()>(&"http://127.0.0.1:5000".parse().unwrap(), "foo", ()) + call::<_, _, _, ()>(&"http://127.0.0.1:5000", "foo", ()) .unwrap() .unwrap(); }); let t2 = std::thread::spawn(|| { - call::<_, _, ()>(&"http://127.0.0.1:5000".parse().unwrap(), "bar", ()) + call::<_, _, _, ()>(&"http://127.0.0.1:5000", "bar", ()) .unwrap() .unwrap(); }); let t3 = std::thread::spawn(|| { - call::<_, _, ()>(&"http://127.0.0.1:5000".parse().unwrap(), "foo", ()) + call::<_, _, _, ()>(&"http://127.0.0.1:5000", "foo", ()) .unwrap() .unwrap(); }); let t4 = std::thread::spawn(|| { - call::<_, _, ()>(&"http://127.0.0.1:5000".parse().unwrap(), "bar", ()) + call::<_, _, _, ()>(&"http://127.0.0.1:5000", "bar", ()) .unwrap() .unwrap(); }); diff --git a/src/client.rs b/src/client.rs index c92841b..bcbb184 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,26 +1,24 @@ use super::error::{Result, ResultExt}; use super::xmlfmt::{from_params, into_params, parse, Call, Fault, Params, Response}; -use hyper::{self, Client as HyperClient}; use serde::{Deserialize, Serialize}; use std; -use Url; +use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; -use hyper::header::Headers; -header! { (ContentType, "ContentType") => [String] } - -pub fn call_value(uri: &Url, name: Tkey, params: Params) -> Result +pub fn call_value(uri: &URL, name: Tkey, params: Params) -> Result where + URL: reqwest::IntoUrl + Clone, Tkey: Into, { Client::new()?.call_value(uri, name, params) } -pub fn call<'a, Tkey, Treq, Tres>( - uri: &Url, +pub fn call<'a, URL, Tkey, Treq, Tres>( + uri: &URL, name: Tkey, req: Treq, ) -> Result> where + URL: reqwest::IntoUrl + Clone, Tkey: Into, Treq: Serialize, Tres: Deserialize<'a>, @@ -29,34 +27,33 @@ where } pub struct Client { - client: HyperClient, + client: reqwest::blocking::Client, } impl Client { pub fn new() -> Result { - let client = HyperClient::new(); + let client = reqwest::blocking::Client::new(); Ok(Client { client }) } - pub fn call_value(&mut self, uri: &Url, name: Tkey, params: Params) -> Result + pub fn call_value(&mut self, uri: &URL, name: Tkey, params: Params) -> Result where + URL: reqwest::IntoUrl + Clone, Tkey: Into, { use super::xmlfmt::value::ToXml; - let body_str = Call { + let body = Call { name: name.into(), params, } .to_xml(); - let bytes: &[u8] = body_str.as_bytes(); - let body = hyper::client::Body::BufBody(bytes, bytes.len()); - let mut headers = Headers::new(); - headers.set(ContentType("xml".to_owned())); + let mut headers = HeaderMap::new(); + headers.insert(CONTENT_TYPE, HeaderValue::from_static("text/xml")); let response = self .client - .post(uri.as_ref()) + .post(uri.clone()) .headers(headers) .body(body) .send() @@ -65,13 +62,14 @@ impl Client { parse::response(response).map_err(Into::into) } - pub fn call<'a, Tkey, Treq, Tres>( + pub fn call<'a, URL, Tkey, Treq, Tres>( &mut self, - uri: &Url, + uri: &URL, name: Tkey, req: Treq, ) -> Result> where + URL: reqwest::IntoUrl + Clone, Tkey: Into, Treq: Serialize, Tres: Deserialize<'a>, diff --git a/src/lib.rs b/src/lib.rs index 12e757f..e3418fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,6 @@ extern crate base64; #[macro_use] extern crate error_chain; #[macro_use] -extern crate hyper; -#[macro_use] extern crate lazy_static; extern crate regex; #[macro_use] @@ -15,13 +13,13 @@ pub extern crate rouille; extern crate serde_bytes; extern crate serde_xml_rs; extern crate xml; +pub extern crate reqwest; pub mod client; pub mod error; pub mod server; mod xmlfmt; -pub use client::{call, call_value, Client}; -pub use hyper::Url; -pub use server::Server; -pub use xmlfmt::{from_params, into_params, Call, Fault, Params, Response, Value}; +pub use crate::client::{call, call_value, Client}; +pub use crate::server::Server; +pub use crate::xmlfmt::{from_params, into_params, Call, Fault, Params, Response, Value}; diff --git a/src/server.rs b/src/server.rs index af74f06..a64ecf8 100644 --- a/src/server.rs +++ b/src/server.rs @@ -135,7 +135,6 @@ where F: Send + Sync + 'static + Fn(&rouille::Request) -> rouille::Response, { server: rouille::Server, - // server: hyper::Server, } impl BoundServer