Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ regex = { version = "1.12.2", default-features = false }
reqwest = { version = "0.13.1", default-features = false }
ring = { version = "0.17.14", default-features = false }
rmp-serde = { version = "1.3.0", default-features = false }
ruma = { git = "https://github.com/ruma/ruma", rev = "2455c71ec8bd16318397865d9c6e231e792cb15e", features = [
ruma = { git = "https://github.com/ruma/ruma", rev = "03ca65151f40304e044f89d8e9e18b68cb9e4f29", features = [
"client-api-c",
"compat-unset-avatar",
"compat-upload-signatures",
Expand Down
1 change: 0 additions & 1 deletion crates/matrix-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ ruma = { workspace = true, features = [
"unstable-msc2448",
"unstable-msc3930",
"unstable-msc3245-v1-compat",
"unstable-msc4230",
"unstable-msc4108",
"unstable-msc4278",
] }
Expand Down
5 changes: 2 additions & 3 deletions crates/matrix-sdk/src/client/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm, boxed_into_future};
use oauth2::{RequestTokenError, basic::BasicErrorResponseType};
use ruma::api::{
OutgoingRequest,
auth_scheme::{AuthScheme, SendAccessToken},
client::{error::ErrorKind, media},
error::FromHttpResponseError,
path_builder::PathBuilder,
Expand All @@ -35,7 +34,7 @@ use crate::{
authentication::oauth::OAuthError,
config::RequestConfig,
error::{HttpError, HttpResult},
http_client::SupportedPathBuilder,
http_client::{SupportedAuthScheme, SupportedPathBuilder},
media::MediaError,
};

Expand Down Expand Up @@ -80,7 +79,7 @@ impl<R> SendRequest<R> {
impl<R> IntoFuture for SendRequest<R>
where
R: OutgoingRequest + Clone + Debug + SendOutsideWasm + SyncOutsideWasm + 'static,
for<'a> R::Authentication: AuthScheme<Input<'a> = SendAccessToken<'a>>,
R::Authentication: SupportedAuthScheme,
R::PathBuilder: SupportedPathBuilder,
for<'a> <R::PathBuilder as PathBuilder>::Input<'a>: SendOutsideWasm + SyncOutsideWasm,
R::IncomingResponse: SendOutsideWasm + SyncOutsideWasm,
Expand Down
7 changes: 3 additions & 4 deletions crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use ruma::{
RoomAliasId, RoomId, RoomOrAliasId, ServerName, UInt, UserId,
api::{
FeatureFlag, MatrixVersion, Metadata, OutgoingRequest, SupportedVersions,
auth_scheme::{AuthScheme, SendAccessToken},
client::{
account::whoami,
alias::{create_alias, delete_alias, get_alias},
Expand Down Expand Up @@ -108,7 +107,7 @@ use crate::{
EventHandler, EventHandlerContext, EventHandlerDropGuard, EventHandlerHandle,
EventHandlerStore, ObservableEventHandler, SyncEvent,
},
http_client::{HttpClient, SupportedPathBuilder},
http_client::{HttpClient, SupportedAuthScheme, SupportedPathBuilder},
latest_events::LatestEvents,
media::MediaError,
notification_settings::NotificationSettings,
Expand Down Expand Up @@ -1923,7 +1922,7 @@ impl Client {
pub fn send<Request>(&self, request: Request) -> SendRequest<Request>
where
Request: OutgoingRequest + Clone + Debug,
for<'a> Request::Authentication: AuthScheme<Input<'a> = SendAccessToken<'a>>,
Request::Authentication: SupportedAuthScheme,
Request::PathBuilder: SupportedPathBuilder,
for<'a> <Request::PathBuilder as PathBuilder>::Input<'a>: SendOutsideWasm + SyncOutsideWasm,
HttpError: From<FromHttpResponseError<Request::EndpointError>>,
Expand All @@ -1944,7 +1943,7 @@ impl Client {
) -> HttpResult<Request::IncomingResponse>
where
Request: OutgoingRequest + Debug,
for<'a> Request::Authentication: AuthScheme<Input<'a> = SendAccessToken<'a>>,
Request::Authentication: SupportedAuthScheme,
Request::PathBuilder: SupportedPathBuilder,
for<'a> <Request::PathBuilder as PathBuilder>::Input<'a>: SendOutsideWasm + SyncOutsideWasm,
HttpError: From<FromHttpResponseError<Request::EndpointError>>,
Expand Down
56 changes: 52 additions & 4 deletions crates/matrix-sdk/src/http_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use http::Method;
use matrix_sdk_base::SendOutsideWasm;
use ruma::api::{
OutgoingRequest, SupportedVersions,
auth_scheme::{AuthScheme, SendAccessToken},
auth_scheme::{self, AuthScheme, SendAccessToken},
error::{FromHttpResponseError, IntoHttpError},
path_builder,
};
Expand Down Expand Up @@ -109,7 +109,7 @@ impl HttpClient {
) -> Result<http::Request<Bytes>, IntoHttpError>
where
R: OutgoingRequest + Debug,
for<'a> R::Authentication: AuthScheme<Input<'a> = SendAccessToken<'a>>,
R::Authentication: SupportedAuthScheme,
{
trace!(request_type = type_name::<R>(), "Serializing request");

Expand All @@ -121,9 +121,14 @@ impl HttpClient {
},
None => SendAccessToken::None,
};
let authentication_input = R::Authentication::authentication_input(send_access_token);

let request = request
.try_into_http_request::<BytesMut>(&homeserver, send_access_token, path_builder_input)?
.try_into_http_request::<BytesMut>(
&homeserver,
authentication_input,
path_builder_input,
)?
.map(|body| body.freeze());

Ok(request)
Expand Down Expand Up @@ -154,7 +159,7 @@ impl HttpClient {
) -> Result<R::IncomingResponse, HttpError>
where
R: OutgoingRequest + Debug,
for<'a> R::Authentication: AuthScheme<Input<'a> = SendAccessToken<'a>>,
R::Authentication: SupportedAuthScheme,
HttpError: From<FromHttpResponseError<R::EndpointError>>,
{
let config = match config {
Expand Down Expand Up @@ -255,6 +260,49 @@ async fn response_to_http_response(
///
/// This trait can also be implemented for custom
/// [`PathBuilder`](path_builder::PathBuilder)s if necessary.
pub trait SupportedAuthScheme: AuthScheme {
fn authentication_input(access_token: SendAccessToken<'_>) -> Self::Input<'_>;
}

impl SupportedAuthScheme for auth_scheme::NoAccessToken {
fn authentication_input(access_token: SendAccessToken<'_>) -> Self::Input<'_> {
access_token
}
}

impl SupportedAuthScheme for auth_scheme::AccessToken {
fn authentication_input(access_token: SendAccessToken<'_>) -> Self::Input<'_> {
access_token
}
}

impl SupportedAuthScheme for auth_scheme::AccessTokenOptional {
fn authentication_input(access_token: SendAccessToken<'_>) -> Self::Input<'_> {
access_token
}
}

impl SupportedAuthScheme for auth_scheme::AppserviceToken {
fn authentication_input(access_token: SendAccessToken<'_>) -> Self::Input<'_> {
access_token
}
}

impl SupportedAuthScheme for auth_scheme::AppserviceTokenOptional {
fn authentication_input(access_token: SendAccessToken<'_>) -> Self::Input<'_> {
access_token
}
}

impl SupportedAuthScheme for auth_scheme::NoAuthentication {
fn authentication_input(_access_token: SendAccessToken<'_>) -> Self::Input<'_> {}
}

/// Marker trait to identify the path builders that the
/// [`Client`](crate::Client) supports.
///
/// This trait can also be implemented for custom
/// [`PathBuilder`](path_builder::PathBuilder)s if necessary.
pub trait SupportedPathBuilder: path_builder::PathBuilder {
fn get_path_builder_input(
client: &crate::Client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ async fn test_room_attachment_send_is_animated() {
"mimetype": "image/jpeg",
"h": 600,
"w": 800,
"org.matrix.msc4230.is_animated": false,
"is_animated": false,
}
}))
.ok(expected_event_id)
Expand Down
Loading