Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
1. fix context to base64 method always encode default context
2. add helper convertor from string pair to str pair
  • Loading branch information
4t145 committed Oct 12, 2023
1 parent c70ca3d commit 83e0670
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions tardis/src/crypto/crypto_base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ impl TardisCryptoBase64 {

impl TardisContext {
pub fn to_base64(&self) -> TardisResult<String> {
let ctx = TardisContext::default();
let ctx = TardisFuns::json.obj_to_string(&ctx)?;
let ctx = TardisFuns::json.obj_to_string(&self)?;
Ok(TardisCryptoBase64.encode(ctx))
}
}
Expand Down
16 changes: 12 additions & 4 deletions tardis/src/web/web_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl<T: Serialize> TardisRequestBody for Json<'_, T> {
}
}

pub fn string_pair_to_str_pair(p: &(String, String)) -> (&str, &str) {
(&p.0, &p.1)
}

impl TardisWebClient {
pub fn init(WebClientModuleConfig { connect_timeout_sec, .. }: &WebClientModuleConfig) -> TardisResult<TardisWebClient> {
info!("[Tardis.WebClient] Initializing");
Expand Down Expand Up @@ -188,13 +192,17 @@ impl TardisWebClient {
self.to_json::<T>(code, headers, response).await
}

async fn request(
async fn request<K, V>(
&self,
method: Method,
url: impl IntoUrl,
headers: impl IntoIterator<Item = (&str, &str)>,
headers: impl IntoIterator<Item = (K, V)>,
body: impl TardisRequestBody,
) -> TardisResult<(u16, HashMap<String, String>, Response)> {
) -> TardisResult<(u16, HashMap<String, String>, Response)>
where
K: Into<String>,
V: Into<String>,
{
let mut url = url.into_url()?;
TardisFuns::uri.sort_url_query(&mut url);
let method_str = method.to_string();
Expand All @@ -204,7 +212,7 @@ impl TardisWebClient {
result = result.header(key, value);
}
for (key, value) in headers {
result = result.header(key, value);
result = result.header(key.into(), value.into());
}
result = body.apply_on(result);
let response = result.send().await?;
Expand Down

0 comments on commit 83e0670

Please sign in to comment.