From a6d1647d2551b8ab8a33648e97c0a007a3f77c36 Mon Sep 17 00:00:00 2001 From: Pascal Date: Wed, 23 Mar 2022 13:15:55 +0100 Subject: [PATCH 01/11] Working prototype --- Cargo.toml | 12 ++++++- examples/custom-header.rs | 20 ++++++++---- src/error.rs | 2 +- src/lib.rs | 1 - src/parser.rs | 6 ++-- src/request.rs | 16 +++++---- src/transport.rs | 69 +++++++++++++++++++++++++++++++-------- src/value.rs | 2 +- tests/python.rs | 1 + 9 files changed, 94 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 838ce593..07d5ade4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ readme = "README.md" license = "CC0-1.0" name = "xmlrpc" version = "0.15.1" +edition = "2021" # cargo-release configuration [package.metadata.release] @@ -41,11 +42,20 @@ maintenance = { status = "actively-developed" } [dependencies] # public iso8601 = "0.4.0" -reqwest = { version = "0.11.0", features = [ "blocking" ], default-features = false, optional = true } # private mime = { version = "0.3", optional = true } base64 = "0.13.0" xml-rs = "0.8.0" +futures = "0.3.21" + +[dependencies.reqwest] +version = "0.11.*" +default-features = false +optional = true + +[dependencies.tokio] +version = "1.17.*" +features = ["full"] [dev-dependencies] version-sync = "0.9" diff --git a/examples/custom-header.rs b/examples/custom-header.rs index bc310390..206459aa 100644 --- a/examples/custom-header.rs +++ b/examples/custom-header.rs @@ -3,10 +3,11 @@ extern crate reqwest; extern crate xmlrpc; +use futures::executor::block_on; use xmlrpc::http::{build_headers, check_response}; use xmlrpc::{Request, Transport}; -use reqwest::blocking::{Client, RequestBuilder, Response}; +use reqwest::{Client, RequestBuilder}; use reqwest::header::COOKIE; use std::error::Error; @@ -15,22 +16,27 @@ use std::error::Error; struct MyTransport(RequestBuilder); impl Transport for MyTransport { - type Stream = Response; + type Stream = &'static[u8]; - fn transmit(self, request: &Request) -> Result> { + fn transmit(self, request: &Request) -> Result> { let mut body = Vec::new(); request .write_as_xml(&mut body) .expect("could not write request to buffer (this should never happen)"); - let response = build_headers(self.0, body.len() as u64) + let response = async move {build_headers(self.0, body.len() as u64) .header(COOKIE, "SESSION=123abc") // Our custom header will be a `Cookie` header .body(body) - .send()?; + .send().await.unwrap()}; + + let resp = block_on(response); - check_response(&response)?; + check_response(&resp)?; - Ok(response) + let rs = async move {resp.text().await.unwrap()}; + let rv = block_on(rs); + + Ok(rv) } } diff --git a/src/error.rs b/src/error.rs index 925412bc..458bf4c2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ //! Defines error types used by this library. -use Value; +use crate::value::Value; use xml::common::TextPosition; use xml::reader::Error as XmlError; diff --git a/src/lib.rs b/src/lib.rs index 7dd870f2..85a30583 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,6 @@ #![doc(html_root_url = "https://docs.rs/xmlrpc/0.15.1")] #![warn(missing_debug_implementations)] -#![warn(rust_2018_idioms)] #![warn(missing_docs)] extern crate base64; diff --git a/src/parser.rs b/src/parser.rs index 48fd1f68..a14caac6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,7 +1,7 @@ //! XML-RPC response parser. -use error::ParseError; -use {Fault, Value}; +use crate::error::{ParseError, Fault}; +use crate::value::Value; use base64; use iso8601::datetime; @@ -353,7 +353,7 @@ pub fn parse_response(reader: &mut R) -> ParseResult { mod tests { use super::*; - use error::Fault; + use crate::error::Fault; use Value; use std::fmt::Debug; diff --git a/src/request.rs b/src/request.rs index e59246de..cd999dc4 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,11 +1,11 @@ #[cfg(feature = "http")] extern crate reqwest; -use error::{Error, RequestErrorKind}; -use parser::parse_response; -use transport::Transport; -use utils::escape_xml; -use Value; +use crate::error::{Error, RequestErrorKind}; +use crate::parser::parse_response; +use crate::transport::Transport; +use crate::utils::escape_xml; +use crate::value::Value; use std::collections::BTreeMap; use std::io::{self, Write}; @@ -77,10 +77,12 @@ impl<'a> Request<'a> { /// [`call_url`]: #method.call_url /// [`Transport`]: trait.Transport.html pub fn call(&self, transport: T) -> Result { - let mut reader = transport + let tr = transport .transmit(self) .map_err(RequestErrorKind::TransportError)?; + let mut reader = tr.as_bytes(); + let response = parse_response(&mut reader).map_err(RequestErrorKind::ParseError)?; let value = response.map_err(RequestErrorKind::Fault)?; @@ -111,7 +113,7 @@ impl<'a> Request<'a> { // While we could implement `Transport` for `T: IntoUrl`, such an impl might not be // completely obvious (as it applies to `&str`), so I've added this method instead. // Might want to reconsider if someone has an objection. - self.call(reqwest::blocking::Client::new().post(url)) + self.call(reqwest::Client::new().post(url)) } /// Formats this `Request` as a UTF-8 encoded XML document. diff --git a/src/transport.rs b/src/transport.rs index 4b76d1e4..6f3f2087 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,5 +1,4 @@ -use Request; - +use crate::request::Request; use std::error::Error; use std::io::Read; @@ -35,7 +34,7 @@ pub trait Transport { /// return an appropriate [`Error`] to the caller. /// /// [`Error`]: struct.Error.html - fn transmit(self, request: &Request<'_>) -> Result>; + fn transmit(self, request: &Request<'_>) -> std::result::Result>; } // FIXME: Link to `Transport` and `RequestBuilder` using intra-rustdoc links. Relative links break @@ -66,9 +65,11 @@ pub mod http { extern crate reqwest; use self::mime::Mime; - use self::reqwest::blocking::RequestBuilder; + use self::reqwest::RequestBuilder; use self::reqwest::header::{CONTENT_LENGTH, CONTENT_TYPE, USER_AGENT}; - use {Request, Transport}; + use crate::request::Request; + use crate::transport::Transport; + use tokio::runtime::Runtime; use std::error::Error; use std::str::FromStr; @@ -92,10 +93,18 @@ pub mod http { .header(CONTENT_LENGTH, body_len) } + // fn send_request(builder: RequestBuilder, body: Vec) -> reqwest::Response { + // let body = build_headers(builder, body.len() as u64).body(body); + // let resp = async move {body.send().await}; + + // std::future::block_on(resp) + // } + + /// Checks that a reqwest `Response` has a status code indicating success and verifies certain /// headers. pub fn check_response( - response: &reqwest::blocking::Response, + response: &reqwest::Response, ) -> Result<(), Box> { // This is essentially an open-coded version of `Response::error_for_status` that does not // consume the response. @@ -133,23 +142,55 @@ pub mod http { /// The request will be sent as specified in the XML-RPC specification: A default `User-Agent` /// will be set, along with the correct `Content-Type` and `Content-Length`. impl Transport for RequestBuilder { - type Stream = reqwest::blocking::Response; + //type Stream = reqwest::Response; + type Stream = &'static[u8]; fn transmit( self, request: &Request<'_>, - ) -> Result> { + ) -> Result> { // First, build the body XML let mut body = Vec::new(); // This unwrap never panics as we are using `Vec` as a `Write` implementor, // and not doing anything else that could return an `Err` in `write_as_xml()`. request.write_as_xml(&mut body).unwrap(); - - let response = build_headers(self, body.len() as u64).body(body).send()?; - - check_response(&response)?; - - Ok(response) + // async part needs to go to separate thread because of interference with caller + // see https://stackoverflow.com/questions/52521201/how-do-i-synchronously-return-a-value-calculated-in-an-asynchronous-future-in-st + // https://stackoverflow.com/questions/62536566/how-can-i-create-a-tokio-runtime-inside-another-tokio-runtime-without-getting-th + + // check https://stackoverflow.com/questions/61996298/using-rust-libraries-reqwest-and-select-in-conjunction + // let resp = async move { + // match build_headers(self, body.len() as u64).body(body).send().await { + // Ok(r) => Ok(r), + // Err(e) => Err(e) + // } + // }; + // //let response: reqwest::Response; + // let response = std::thread::spawn( || { match Runtime::new().unwrap().block_on(resp) { + // Ok(o) => o, + // Err(_) => () + // } }).join(); + + // if response.is_ok() { + // check_response(&response.as_ref().unwrap())?; + // } + + // let bv = async move { + // match response.unwrap().text().await { + // Ok(r) => Ok(r), + // Err(e) => Err(e) + // } + // }; + // let rv = std::thread::spawn( || {Runtime::new().unwrap().block_on(bv).unwrap()}).join(); + + // rewrite all, async block + let ab = async move { + let rv = build_headers(self, body.len() as u64).body(body).send().await?; + check_response(&rv).unwrap(); + rv.text().await + }; + + std::thread::spawn( || {Runtime::new().unwrap().block_on(ab)}).join().unwrap().map_err(|error| Box::new(error) as Box) } } } diff --git a/src/value.rs b/src/value.rs index fa556eb4..b7029d61 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,6 +1,6 @@ //! Contains the different types of values understood by XML-RPC. -use utils::{escape_xml, format_datetime}; +use crate::utils::{escape_xml, format_datetime}; use base64::encode; use iso8601::DateTime; diff --git a/tests/python.rs b/tests/python.rs index 089d7582..d1207350 100644 --- a/tests/python.rs +++ b/tests/python.rs @@ -96,6 +96,7 @@ fn run_tests() { Fault::from_value(&results[2]).expect("expected fault as third result"); } + fn main() { let mut reaper = match setup() { Ok(reap) => reap, From e7ddb7ac1d759f75a9d5da0fcc4e104787a043e9 Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 28 Mar 2022 14:30:16 +0200 Subject: [PATCH 02/11] Use Cursor as Stream Type --- CHANGELOG.md | 6 +++++- Cargo.toml | 3 ++- examples/custom-header.rs | 7 ++++--- src/request.rs | 4 ++-- src/transport.rs | 20 +++++++++++++++----- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33ef79ee..77a4fa17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ ## Unreleased -No changes. +* Updated to Rust 2021 Syntax +* Updated `reqwest`to 0.11.1 + +- Added `async` feature +- Refactored to not use `reqwest::blocking` ## 0.15.1 - 2021-11-02 diff --git a/Cargo.toml b/Cargo.toml index 07d5ade4..3a7414d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ categories = ["network-programming", "encoding"] readme = "README.md" license = "CC0-1.0" name = "xmlrpc" -version = "0.15.1" +version = "0.16.0" edition = "2021" # cargo-release configuration @@ -62,6 +62,7 @@ version-sync = "0.9" [features] http = ["reqwest", "mime"] +async = ["reqwest", "mime"] tls = ["reqwest/default-tls"] default = ["http", "tls"] diff --git a/examples/custom-header.rs b/examples/custom-header.rs index 206459aa..ed943629 100644 --- a/examples/custom-header.rs +++ b/examples/custom-header.rs @@ -11,14 +11,15 @@ use reqwest::{Client, RequestBuilder}; use reqwest::header::COOKIE; use std::error::Error; +use std::io::Cursor; /// Custom transport that adds a cookie header. struct MyTransport(RequestBuilder); impl Transport for MyTransport { - type Stream = &'static[u8]; + type Stream = Cursor; - fn transmit(self, request: &Request) -> Result> { + fn transmit(self, request: &Request) -> Result> { let mut body = Vec::new(); request .write_as_xml(&mut body) @@ -34,7 +35,7 @@ impl Transport for MyTransport { check_response(&resp)?; let rs = async move {resp.text().await.unwrap()}; - let rv = block_on(rs); + let rv = Cursor::new(block_on(rs)); Ok(rv) } diff --git a/src/request.rs b/src/request.rs index cd999dc4..60c8dd5c 100644 --- a/src/request.rs +++ b/src/request.rs @@ -77,11 +77,11 @@ impl<'a> Request<'a> { /// [`call_url`]: #method.call_url /// [`Transport`]: trait.Transport.html pub fn call(&self, transport: T) -> Result { - let tr = transport + let mut reader = transport .transmit(self) .map_err(RequestErrorKind::TransportError)?; - let mut reader = tr.as_bytes(); + //let mut reader = tr.as_bytes(); let response = parse_response(&mut reader).map_err(RequestErrorKind::ParseError)?; diff --git a/src/transport.rs b/src/transport.rs index 6f3f2087..5e1a8c47 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -34,7 +34,7 @@ pub trait Transport { /// return an appropriate [`Error`] to the caller. /// /// [`Error`]: struct.Error.html - fn transmit(self, request: &Request<'_>) -> std::result::Result>; + fn transmit(self, request: &Request<'_>) -> std::result::Result>; } // FIXME: Link to `Transport` and `RequestBuilder` using intra-rustdoc links. Relative links break @@ -64,6 +64,7 @@ pub mod http { extern crate mime; extern crate reqwest; + use std::io::Cursor; use self::mime::Mime; use self::reqwest::RequestBuilder; use self::reqwest::header::{CONTENT_LENGTH, CONTENT_TYPE, USER_AGENT}; @@ -137,18 +138,24 @@ pub mod http { Ok(()) } + // private execution of the transport + // fn transport_exec(builder: RequestBuilder) -> Result<&'static[u8], Box> { + + // } + /// Use a `RequestBuilder` as the transport. /// /// The request will be sent as specified in the XML-RPC specification: A default `User-Agent` /// will be set, along with the correct `Content-Type` and `Content-Length`. impl Transport for RequestBuilder { //type Stream = reqwest::Response; - type Stream = &'static[u8]; + //type Stream = &'static[u8]; + type Stream = Cursor; fn transmit( self, request: &Request<'_>, - ) -> Result> { + ) -> Result> { // First, build the body XML let mut body = Vec::new(); // This unwrap never panics as we are using `Vec` as a `Write` implementor, @@ -190,7 +197,10 @@ pub mod http { rv.text().await }; - std::thread::spawn( || {Runtime::new().unwrap().block_on(ab)}).join().unwrap().map_err(|error| Box::new(error) as Box) + let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(ab)}).join().unwrap().unwrap();//.map_err(|error| Box::new(error) as Box); + let rc = Cursor::new(rs); + + Ok(rc) //.map_err(|error| Box::new(error) as Box) } } -} +} \ No newline at end of file From 279ddbcff7ab757220dabfab62e286b12ee6b23b Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 28 Mar 2022 15:39:17 +0200 Subject: [PATCH 03/11] Cleanup --- Cargo.toml | 1 - src/transport.rs | 58 +++++++++--------------------------------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a7414d6..6188a074 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,6 @@ version-sync = "0.9" [features] http = ["reqwest", "mime"] -async = ["reqwest", "mime"] tls = ["reqwest/default-tls"] default = ["http", "tls"] diff --git a/src/transport.rs b/src/transport.rs index 5e1a8c47..34968368 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -94,14 +94,6 @@ pub mod http { .header(CONTENT_LENGTH, body_len) } - // fn send_request(builder: RequestBuilder, body: Vec) -> reqwest::Response { - // let body = build_headers(builder, body.len() as u64).body(body); - // let resp = async move {body.send().await}; - - // std::future::block_on(resp) - // } - - /// Checks that a reqwest `Response` has a status code indicating success and verifies certain /// headers. pub fn check_response( @@ -138,18 +130,12 @@ pub mod http { Ok(()) } - // private execution of the transport - // fn transport_exec(builder: RequestBuilder) -> Result<&'static[u8], Box> { - - // } - /// Use a `RequestBuilder` as the transport. /// /// The request will be sent as specified in the XML-RPC specification: A default `User-Agent` /// will be set, along with the correct `Content-Type` and `Content-Length`. impl Transport for RequestBuilder { - //type Stream = reqwest::Response; - //type Stream = &'static[u8]; + //Chose Cursor as Cursor implements the Read Trait and has ownership type Stream = Cursor; fn transmit( @@ -161,46 +147,22 @@ pub mod http { // This unwrap never panics as we are using `Vec` as a `Write` implementor, // and not doing anything else that could return an `Err` in `write_as_xml()`. request.write_as_xml(&mut body).unwrap(); - // async part needs to go to separate thread because of interference with caller - // see https://stackoverflow.com/questions/52521201/how-do-i-synchronously-return-a-value-calculated-in-an-asynchronous-future-in-st - // https://stackoverflow.com/questions/62536566/how-can-i-create-a-tokio-runtime-inside-another-tokio-runtime-without-getting-th - // check https://stackoverflow.com/questions/61996298/using-rust-libraries-reqwest-and-select-in-conjunction - // let resp = async move { - // match build_headers(self, body.len() as u64).body(body).send().await { - // Ok(r) => Ok(r), - // Err(e) => Err(e) - // } - // }; - // //let response: reqwest::Response; - // let response = std::thread::spawn( || { match Runtime::new().unwrap().block_on(resp) { - // Ok(o) => o, - // Err(_) => () - // } }).join(); - - // if response.is_ok() { - // check_response(&response.as_ref().unwrap())?; - // } - - // let bv = async move { - // match response.unwrap().text().await { - // Ok(r) => Ok(r), - // Err(e) => Err(e) - // } - // }; - // let rv = std::thread::spawn( || {Runtime::new().unwrap().block_on(bv).unwrap()}).join(); - - // rewrite all, async block - let ab = async move { + // async part needs to go to separate thread because of interference with caller + let async_transport = async move { let rv = build_headers(self, body.len() as u64).body(body).send().await?; check_response(&rv).unwrap(); rv.text().await }; - let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(ab)}).join().unwrap().unwrap();//.map_err(|error| Box::new(error) as Box); - let rc = Cursor::new(rs); + // execute the async transport in an own thread, to the blocking async execution can be used + let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(async_transport)}).join().unwrap().map_err(|error| Box::new(error) as Box); - Ok(rc) //.map_err(|error| Box::new(error) as Box) + // error handling of the return value + match rs { + Ok(o) => Ok(Cursor::new(o)), + Err(error) => Err(error as Box), + } } } } \ No newline at end of file From 351bc8409d3902ed56b92801edfa28bef4e33e1c Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 28 Mar 2022 15:51:09 +0200 Subject: [PATCH 04/11] update dependencies --- CHANGELOG.md | 6 +++--- Cargo.toml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77a4fa17..817f81dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,10 @@ ## Unreleased * Updated to Rust 2021 Syntax -* Updated `reqwest`to 0.11.1 +* Updated `reqwest`to 0.11.10 +* Added `tokio` dependency for async runtime (feature rt-multi-thread) -- Added `async` feature -- Refactored to not use `reqwest::blocking` +- Refactored to not use `reqwest::blocking`, all interfaces stay stable ## 0.15.1 - 2021-11-02 diff --git a/Cargo.toml b/Cargo.toml index 6188a074..0fc5ca5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,13 +49,13 @@ xml-rs = "0.8.0" futures = "0.3.21" [dependencies.reqwest] -version = "0.11.*" +version = "0.11.10" default-features = false optional = true [dependencies.tokio] -version = "1.17.*" -features = ["full"] +version = "1.17.0" +features = ["rt-multi-thread"] [dev-dependencies] version-sync = "0.9" From ae4d5af2bbbfbf09d628d155650417f1e9cb57e0 Mon Sep 17 00:00:00 2001 From: Pascal Date: Thu, 18 Aug 2022 22:51:36 +0200 Subject: [PATCH 05/11] updated dependencies modified: Cargo.toml --- Cargo.toml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0fc5ca5e..beee6ecd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,21 +41,12 @@ maintenance = { status = "actively-developed" } [dependencies] # public -iso8601 = "0.4.0" +iso8601 = "0.5.0" +reqwest = { version = "0.11.0", features = [ "blocking" ], default-features = false, optional = true } # private mime = { version = "0.3", optional = true } base64 = "0.13.0" -xml-rs = "0.8.0" -futures = "0.3.21" - -[dependencies.reqwest] -version = "0.11.10" -default-features = false -optional = true - -[dependencies.tokio] -version = "1.17.0" -features = ["rt-multi-thread"] +xml-rs = "0.8.4" [dev-dependencies] version-sync = "0.9" From 419c8183d596dc54a88116acd6ae24ef365fcfec Mon Sep 17 00:00:00 2001 From: Pascal Date: Thu, 18 Aug 2022 22:55:08 +0200 Subject: [PATCH 06/11] Restore asynch part --- Cargo.toml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index beee6ecd..75b37c2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,11 +42,20 @@ maintenance = { status = "actively-developed" } [dependencies] # public iso8601 = "0.5.0" -reqwest = { version = "0.11.0", features = [ "blocking" ], default-features = false, optional = true } # private mime = { version = "0.3", optional = true } base64 = "0.13.0" xml-rs = "0.8.4" +futures = "0.3.21" + +[dependencies.reqwest] +version = "0.11.10" +default-features = false +optional = true + +[dependencies.tokio] +version = "1.17.0" +features = ["rt-multi-thread"] [dev-dependencies] version-sync = "0.9" From 4b4ff98af64850fce3904f1ba0bbf913aa93d9dc Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 19 Dec 2022 21:22:57 +0100 Subject: [PATCH 07/11] Correct tests, propagate error from async to result --- README.md | 2 +- src/lib.rs | 2 +- src/transport.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d831ace6..da9e174b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Start by adding an entry to your `Cargo.toml`: ```toml [dependencies] -xmlrpc = "0.15.1" +xmlrpc = "0.16.0" ``` Then import the crate into your Rust code: diff --git a/src/lib.rs b/src/lib.rs index 85a30583..8d974e25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ //! //! [XML-RPC specification]: http://xmlrpc.scripting.com/spec.html -#![doc(html_root_url = "https://docs.rs/xmlrpc/0.15.1")] +#![doc(html_root_url = "https://docs.rs/xmlrpc/0.16.0")] #![warn(missing_debug_implementations)] #![warn(missing_docs)] diff --git a/src/transport.rs b/src/transport.rs index 34968368..f4403a17 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -151,7 +151,7 @@ pub mod http { // async part needs to go to separate thread because of interference with caller let async_transport = async move { let rv = build_headers(self, body.len() as u64).body(body).send().await?; - check_response(&rv).unwrap(); + _ = check_response(&rv); rv.text().await }; From 23f48c821aae0e247ac46081ce9bc03bffe032ad Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 19 Dec 2022 21:30:29 +0100 Subject: [PATCH 08/11] correct error handling --- src/transport.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transport.rs b/src/transport.rs index f4403a17..68fb5377 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -151,7 +151,7 @@ pub mod http { // async part needs to go to separate thread because of interference with caller let async_transport = async move { let rv = build_headers(self, body.len() as u64).body(body).send().await?; - _ = check_response(&rv); + _ = check_response(&rv).expect("No valid response"); rv.text().await }; From ad688b160f5fd88bf7eefaf552faccbaea8f87c1 Mon Sep 17 00:00:00 2001 From: Pascal Date: Tue, 20 Dec 2022 21:51:29 +0100 Subject: [PATCH 09/11] improve error handling --- src/transport.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/transport.rs b/src/transport.rs index 68fb5377..f67f5239 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -72,7 +72,7 @@ pub mod http { use crate::transport::Transport; use tokio::runtime::Runtime; - use std::error::Error; + use std::error::{Error, self}; use std::str::FromStr; /// Appends all HTTP headers required by the XML-RPC specification to the `RequestBuilder`. @@ -156,13 +156,16 @@ pub mod http { }; // execute the async transport in an own thread, to the blocking async execution can be used - let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(async_transport)}).join().unwrap().map_err(|error| Box::new(error) as Box); + let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(async_transport)}).join(); // error handling of the return value - match rs { + match rs.unwrap() { Ok(o) => Ok(Cursor::new(o)), - Err(error) => Err(error as Box), + Err(error) => Err(Box::new(error)), } + + //let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(async_transport)}).join().unwrap().map_err(|error| Box::new(error) as Box); + } } } \ No newline at end of file From 65cc35b19f54374b07fcb3edf80744da39a61cbf Mon Sep 17 00:00:00 2001 From: Pascal Date: Wed, 21 Dec 2022 21:20:18 +0100 Subject: [PATCH 10/11] Fix error handling --- src/transport.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transport.rs b/src/transport.rs index f67f5239..a2f6685e 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -156,12 +156,12 @@ pub mod http { }; // execute the async transport in an own thread, to the blocking async execution can be used - let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(async_transport)}).join(); + let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(async_transport)}).join().expect("Expected result from async thread"); // error handling of the return value - match rs.unwrap() { + match rs { Ok(o) => Ok(Cursor::new(o)), - Err(error) => Err(Box::new(error)), + Err(err) => Err(Box::new(err) as Box), } //let rs = std::thread::spawn( || {Runtime::new().unwrap().block_on(async_transport)}).join().unwrap().map_err(|error| Box::new(error) as Box); From 8a8cca19905d63a3a9bae9aca4f7afbcbcec9123 Mon Sep 17 00:00:00 2001 From: Pascal Date: Wed, 21 Dec 2022 22:01:22 +0100 Subject: [PATCH 11/11] Remove unused imports --- src/transport.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transport.rs b/src/transport.rs index a2f6685e..e1f66842 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -72,7 +72,7 @@ pub mod http { use crate::transport::Transport; use tokio::runtime::Runtime; - use std::error::{Error, self}; + use std::error::Error; use std::str::FromStr; /// Appends all HTTP headers required by the XML-RPC specification to the `RequestBuilder`. @@ -151,7 +151,7 @@ pub mod http { // async part needs to go to separate thread because of interference with caller let async_transport = async move { let rv = build_headers(self, body.len() as u64).body(body).send().await?; - _ = check_response(&rv).expect("No valid response"); + check_response(&rv).expect("No valid response"); rv.text().await };