Skip to content

Commit 84796ab

Browse files
stefanceriupoljar
authored andcommitted
feat(ffi): expose method for sending generic GET requests through the SDK's inner HTTP client.
1 parent 6464d21 commit 84796ab

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

bindings/matrix-sdk-ffi/src/client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ impl Client {
420420
}
421421
})))
422422
}
423+
424+
pub async fn get_url(&self, url: String) -> Result<String, ClientError> {
425+
let http_client = self.inner.http_client();
426+
Ok(http_client.get(url).send().await?.text().await?)
427+
}
423428
}
424429

425430
impl Client {

bindings/matrix-sdk-ffi/src/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Display;
22

33
use matrix_sdk::{
4-
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError,
4+
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError, reqwest,
55
send_queue::RoomSendQueueError, HttpError, IdParseError,
66
NotificationSettingsError as SdkNotificationSettingsError, StoreError,
77
};
@@ -26,6 +26,12 @@ impl From<anyhow::Error> for ClientError {
2626
}
2727
}
2828

29+
impl From<reqwest::Error> for ClientError {
30+
fn from(e: reqwest::Error) -> Self {
31+
Self::new(e)
32+
}
33+
}
34+
2935
impl From<UnexpectedUniFFICallbackError> for ClientError {
3036
fn from(e: UnexpectedUniFFICallbackError) -> Self {
3137
Self::new(e)

crates/matrix-sdk/src/client/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ impl Client {
394394
&self.inner.base_client
395395
}
396396

397+
/// The underlying HTTP client.
398+
pub fn http_client(&self) -> &reqwest::Client {
399+
&self.inner.http_client.inner
400+
}
401+
397402
pub(crate) fn locks(&self) -> &ClientLocks {
398403
&self.inner.locks
399404
}

0 commit comments

Comments
 (0)