-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from lumeohq/dmitry/add-response-patcher
- Loading branch information
Showing
1 changed file
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use async_trait::async_trait; | |
use schema::transport::{Error, Transport}; | ||
use std::{ | ||
fmt::{Debug, Formatter}, | ||
sync::Arc, | ||
time::Duration, | ||
}; | ||
use url::Url; | ||
|
@@ -48,6 +49,7 @@ impl ClientBuilder { | |
config: Config { | ||
uri: uri.clone(), | ||
credentials: None, | ||
response_patcher: None, | ||
auth_type: AuthType::Any, | ||
timeout: Duration::from_secs(5), | ||
}, | ||
|
@@ -59,6 +61,11 @@ impl ClientBuilder { | |
self | ||
} | ||
|
||
pub fn response_patcher(mut self, response_patcher: Option<ResponsePatcher>) -> Self { | ||
self.config.response_patcher = response_patcher; | ||
self | ||
} | ||
|
||
pub fn auth_type(mut self, auth_type: AuthType) -> Self { | ||
self.config.auth_type = auth_type; | ||
self | ||
|
@@ -96,6 +103,7 @@ impl ClientBuilder { | |
struct Config { | ||
uri: Url, | ||
credentials: Option<Credentials>, | ||
response_patcher: Option<ResponsePatcher>, | ||
auth_type: AuthType, | ||
timeout: Duration, | ||
} | ||
|
@@ -122,6 +130,8 @@ impl Debug for Credentials { | |
} | ||
} | ||
|
||
pub type ResponsePatcher = Arc<dyn Fn(&str) -> Result<String, String> + Send + Sync>; | ||
|
||
#[derive(Debug)] | ||
enum RequestAuthType { | ||
Digest(Digest), | ||
|
@@ -226,7 +236,19 @@ impl Client { | |
.map_err(|e| Error::Protocol(e.to_string())) | ||
.and_then(|text| { | ||
debug!(self, "Response body: {}", text); | ||
soap::unsoap(&text).map_err(|e| Error::Protocol(format!("{:?}", e))) | ||
let response = | ||
soap::unsoap(&text).map_err(|e| Error::Protocol(format!("{:?}", e)))?; | ||
if let Some(response_patcher) = &self.config.response_patcher { | ||
match response_patcher(&response) { | ||
Ok(patched) => { | ||
debug!(self, "Response (SOAP unwrapped, patched): {}", patched); | ||
Ok(patched) | ||
} | ||
Err(e) => Err(Error::Protocol(format!("Patching failed: {e}"))), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
FSMaxB
|
||
} | ||
} else { | ||
Ok(response) | ||
} | ||
}) | ||
} else if status == reqwest::StatusCode::UNAUTHORIZED { | ||
match auth_type { | ||
|
error: there is no argument named
e
--> /Users/zero/.cargo/git/checkouts/onvif-rs-92f68257d184bb96/9e80c95/onvif/src/soap/client.rs:247:85
|
247 | ... Err(e) => Err(Error::Protocol(format!("Patching failed: {e}"))),
we have error here.