|
|
@@ -38,6 +38,19 @@ pub trait Transport: Default + Send + Sync + Debug + Clone {
|
|
|
auth: Option<cdk_common::AuthToken>,
|
|
|
) -> Result<R, super::Error>
|
|
|
where
|
|
|
+ R: serde::de::DeserializeOwned,
|
|
|
+ {
|
|
|
+ self.http_get_with_headers(url, auth, &[]).await
|
|
|
+ }
|
|
|
+
|
|
|
+ /// HTTP Get request with custom headers
|
|
|
+ async fn http_get_with_headers<R>(
|
|
|
+ &self,
|
|
|
+ url: url::Url,
|
|
|
+ auth: Option<cdk_common::AuthToken>,
|
|
|
+ custom_headers: &[(&str, &str)],
|
|
|
+ ) -> Result<R, super::Error>
|
|
|
+ where
|
|
|
R: serde::de::DeserializeOwned;
|
|
|
|
|
|
/// HTTP Post request
|
|
|
@@ -49,6 +62,22 @@ pub trait Transport: Default + Send + Sync + Debug + Clone {
|
|
|
) -> Result<R, super::Error>
|
|
|
where
|
|
|
P: serde::Serialize + ?Sized + Send + Sync,
|
|
|
+ R: serde::de::DeserializeOwned,
|
|
|
+ {
|
|
|
+ self.http_post_with_headers(url, auth_token, &[], payload)
|
|
|
+ .await
|
|
|
+ }
|
|
|
+
|
|
|
+ /// HTTP Post request with custom headers
|
|
|
+ async fn http_post_with_headers<P, R>(
|
|
|
+ &self,
|
|
|
+ url: url::Url,
|
|
|
+ auth_token: Option<cdk_common::AuthToken>,
|
|
|
+ custom_headers: &[(&str, &str)],
|
|
|
+ payload: &P,
|
|
|
+ ) -> Result<R, super::Error>
|
|
|
+ where
|
|
|
+ P: serde::Serialize + ?Sized + Send + Sync,
|
|
|
R: serde::de::DeserializeOwned;
|
|
|
}
|
|
|
|
|
|
@@ -135,7 +164,12 @@ impl Transport for Async {
|
|
|
.collect::<Vec<_>>())
|
|
|
}
|
|
|
|
|
|
- async fn http_get<R>(&self, url: Url, auth: Option<AuthToken>) -> Result<R, Error>
|
|
|
+ async fn http_get_with_headers<R>(
|
|
|
+ &self,
|
|
|
+ url: Url,
|
|
|
+ auth: Option<AuthToken>,
|
|
|
+ custom_headers: &[(&str, &str)],
|
|
|
+ ) -> Result<R, Error>
|
|
|
where
|
|
|
R: DeserializeOwned,
|
|
|
{
|
|
|
@@ -146,6 +180,10 @@ impl Transport for Async {
|
|
|
request = request.header(auth.header_key(), auth.to_string());
|
|
|
}
|
|
|
|
|
|
+ for (key, value) in custom_headers {
|
|
|
+ request = request.header(*key, *value);
|
|
|
+ }
|
|
|
+
|
|
|
let response = request
|
|
|
.send()
|
|
|
.await
|
|
|
@@ -163,10 +201,11 @@ impl Transport for Async {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- async fn http_post<P, R>(
|
|
|
+ async fn http_post_with_headers<P, R>(
|
|
|
&self,
|
|
|
url: Url,
|
|
|
auth_token: Option<AuthToken>,
|
|
|
+ custom_headers: &[(&str, &str)],
|
|
|
payload: &P,
|
|
|
) -> Result<R, Error>
|
|
|
where
|
|
|
@@ -180,6 +219,10 @@ impl Transport for Async {
|
|
|
request = request.header(auth.header_key(), auth.to_string());
|
|
|
}
|
|
|
|
|
|
+ for (key, value) in custom_headers {
|
|
|
+ request = request.header(*key, *value);
|
|
|
+ }
|
|
|
+
|
|
|
let response = request
|
|
|
.send()
|
|
|
.await
|