chore: Handle Ruma's new OutgoingRequestExt

https://github.com/ruma/ruma/pull/2537
https://github.com/ruma/ruma/pull/2543
This commit is contained in:
Doug
2026-07-20 12:03:39 +01:00
committed by Jorge Martin Espinosa
parent 5754451d05
commit d643e115b0
7 changed files with 38 additions and 81 deletions

View File

@@ -16,13 +16,11 @@ use matrix_sdk::RumaApiError;
use matrix_sdk_crypto::olm::Curve25519PublicKey;
use ruma::{
api::{
Metadata, OutgoingRequest,
auth_scheme::{AccessTokenOptional, AuthScheme, SendAccessToken},
error::IntoHttpError,
path_builder::PathBuilder,
BytesBody, Metadata, OutgoingRequest, auth_scheme::AccessTokenOptional,
error::IntoHttpError, path_builder::PathBuilder,
},
events::room::EncryptedFile,
exports::{bytes::BufMut, http::Request},
exports::http::Request,
metadata,
};
@@ -58,28 +56,20 @@ impl DownloadAndScanEncryptedMediaRequest {
}
impl OutgoingRequest for DownloadAndScanEncryptedMediaRequest {
type Body = BytesBody;
type EndpointError = RumaApiError;
type IncomingResponse = DownloadAndScanMediaResponse;
fn try_into_http_request<T: Default + BufMut + AsRef<[u8]>>(
fn try_into_http_request_inner(
self,
_base_url: &str,
authentication_input: <Self::Authentication as AuthScheme>::Input<'_>,
path_builder_input: <Self::PathBuilder as PathBuilder>::Input<'_>,
) -> Result<Request<T>, IntoHttpError> {
) -> Result<Request<Self::Body>, IntoHttpError> {
let url = Self::make_endpoint_url(path_builder_input, &self.scanner_url, &[], "")?;
let body = encrypted_file_request_from(self.public_key, &self.encrypted_file)?;
let body = ruma::serde::json_to_buf(&body)?;
let body = BytesBody(ruma::serde::json_to_buf(&body)?);
let mut request = Request::builder().method(Self::METHOD).uri(url).body(body)?;
if let Some(access_token) = authentication_input.get_required_for_endpoint() {
Self::Authentication::add_authentication(
&mut request,
SendAccessToken::IfRequired(access_token),
)?
}
Ok(request)
Ok(Request::builder().method(Self::METHOD).uri(url).body(body)?)
}
}

View File

@@ -15,12 +15,10 @@
use matrix_sdk::RumaApiError;
use ruma::{
api::{
Metadata, OutgoingRequest,
auth_scheme::{AccessTokenOptional, AuthScheme, SendAccessToken},
error::IntoHttpError,
path_builder::PathBuilder,
EmptyBody, Metadata, OutgoingRequest, auth_scheme::AccessTokenOptional,
error::IntoHttpError, path_builder::PathBuilder,
},
exports::{bytes::BufMut, http::Request},
exports::http::Request,
metadata,
};
@@ -60,15 +58,15 @@ impl DownloadAndScanMediaRequest {
}
impl OutgoingRequest for DownloadAndScanMediaRequest {
type Body = EmptyBody;
type EndpointError = RumaApiError;
type IncomingResponse = DownloadAndScanMediaResponse;
fn try_into_http_request<T: Default + BufMut + AsRef<[u8]>>(
fn try_into_http_request_inner(
self,
_base_url: &str,
authentication_input: <Self::Authentication as AuthScheme>::Input<'_>,
path_builder_input: <Self::PathBuilder as PathBuilder>::Input<'_>,
) -> Result<Request<T>, IntoHttpError> {
) -> Result<Request<Self::Body>, IntoHttpError> {
let url = Self::make_endpoint_url(
path_builder_input,
&self.scanner_url,
@@ -76,14 +74,6 @@ impl OutgoingRequest for DownloadAndScanMediaRequest {
"",
)?;
let mut request = Request::builder().method(Self::METHOD).uri(url).body(T::default())?;
if let Some(access_token) = authentication_input.get_required_for_endpoint() {
Self::Authentication::add_authentication(
&mut request,
SendAccessToken::IfRequired(access_token),
)?
}
Ok(request)
Ok(Request::builder().method(Self::METHOD).uri(url).body(EmptyBody)?)
}
}

View File

@@ -15,13 +15,12 @@
use matrix_sdk::RumaApiError;
use ruma::{
api::{
IncomingResponse, Metadata, OutgoingRequest,
auth_scheme::{AuthScheme, NoAuthentication},
EmptyBody, IncomingResponse, Metadata, OutgoingRequest,
auth_scheme::NoAuthentication,
error::{FromHttpResponseError, IntoHttpError},
path_builder::PathBuilder,
},
exports::{
bytes::BufMut,
http::{Request, Response},
serde_json,
},
@@ -53,17 +52,17 @@ impl PublicServerKeyRequest {
}
impl OutgoingRequest for PublicServerKeyRequest {
type Body = EmptyBody;
type EndpointError = RumaApiError;
type IncomingResponse = PublicServerKeyResponse;
fn try_into_http_request<T: Default + BufMut + AsRef<[u8]>>(
fn try_into_http_request_inner(
self,
_base_url: &str,
_authentication_input: <Self::Authentication as AuthScheme>::Input<'_>,
path_builder_input: <Self::PathBuilder as PathBuilder>::Input<'_>,
) -> Result<Request<T>, IntoHttpError> {
) -> Result<Request<Self::Body>, IntoHttpError> {
let url = Self::make_endpoint_url(path_builder_input, &self.scanner_url, &[], "")?;
Ok(Request::builder().method(Self::METHOD).uri(url).body(T::default())?)
Ok(Request::builder().method(Self::METHOD).uri(url).body(EmptyBody)?)
}
}

View File

@@ -12,13 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use matrix_sdk::{RumaApiError, bytes::BufMut, encryption::vodozemac::Curve25519PublicKey};
use matrix_sdk::{RumaApiError, encryption::vodozemac::Curve25519PublicKey};
use ruma::{
api::{
Metadata, OutgoingRequest,
auth_scheme::{AccessTokenOptional, AuthScheme, SendAccessToken},
error::IntoHttpError,
path_builder::PathBuilder,
BytesBody, Metadata, OutgoingRequest, auth_scheme::AccessTokenOptional,
error::IntoHttpError, path_builder::PathBuilder,
},
events::room::EncryptedFile,
exports::http::Request,
@@ -57,29 +55,20 @@ impl EncryptedMediaScanRequest {
}
impl OutgoingRequest for EncryptedMediaScanRequest {
type Body = BytesBody;
type EndpointError = RumaApiError;
type IncomingResponse = MediaScanResponse;
fn try_into_http_request<T: Default + BufMut + AsRef<[u8]>>(
fn try_into_http_request_inner(
self,
_base_url: &str,
authentication_input: <Self::Authentication as AuthScheme>::Input<'_>,
path_builder_input: <Self::PathBuilder as PathBuilder>::Input<'_>,
) -> Result<Request<T>, IntoHttpError> {
) -> Result<Request<Self::Body>, IntoHttpError> {
let url = Self::make_endpoint_url(path_builder_input, &self.scanner_url, &[], "")?;
let body = encrypted_file_request_from(self.public_key, &self.encrypted_file)?;
let body = ruma::serde::json_to_buf(&body)?;
let body = BytesBody(ruma::serde::json_to_buf(&body)?);
let mut request = Request::builder().method(Self::METHOD).uri(url).body(body)?;
if let Some(access_token) = authentication_input.get_required_for_endpoint() {
Self::Authentication::add_authentication(
&mut request,
SendAccessToken::IfRequired(access_token),
)?
}
Ok(request)
Ok(Request::builder().method(Self::METHOD).uri(url).body(body)?)
}
}

View File

@@ -12,13 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use matrix_sdk::{RumaApiError, bytes::BufMut};
use matrix_sdk::RumaApiError;
use ruma::{
api::{
Metadata, OutgoingRequest,
auth_scheme::{AccessTokenOptional, AuthScheme, SendAccessToken},
error::IntoHttpError,
path_builder::PathBuilder,
EmptyBody, Metadata, OutgoingRequest, auth_scheme::AccessTokenOptional,
error::IntoHttpError, path_builder::PathBuilder,
},
exports::http::Request,
metadata,
@@ -52,15 +50,15 @@ impl MediaScanRequest {
}
impl OutgoingRequest for MediaScanRequest {
type Body = EmptyBody;
type EndpointError = RumaApiError;
type IncomingResponse = MediaScanResponse;
fn try_into_http_request<T: Default + BufMut + AsRef<[u8]>>(
fn try_into_http_request_inner(
self,
_base_url: &str,
authentication_input: <Self::Authentication as AuthScheme>::Input<'_>,
path_builder_input: <Self::PathBuilder as PathBuilder>::Input<'_>,
) -> Result<Request<T>, IntoHttpError> {
) -> Result<Request<Self::Body>, IntoHttpError> {
let url = Self::make_endpoint_url(
path_builder_input,
&self.scanner_url,
@@ -68,15 +66,6 @@ impl OutgoingRequest for MediaScanRequest {
"",
)?;
let mut request = Request::builder().method(Self::METHOD).uri(url).body(T::default())?;
if let Some(access_token) = authentication_input.get_required_for_endpoint() {
Self::Authentication::add_authentication(
&mut request,
SendAccessToken::IfRequired(access_token),
)?
}
Ok(request)
Ok(Request::builder().method(Self::METHOD).uri(url).body(EmptyBody)?)
}
}

View File

@@ -23,7 +23,7 @@ use std::{borrow::Cow, fmt};
use matrix_sdk_base::{SessionMeta, store::RoomLoadSettings};
use ruma::{
api::{
OutgoingRequest,
OutgoingRequestExt,
auth_scheme::SendAccessToken,
client::{
account::register,

View File

@@ -30,7 +30,7 @@ use eyeball::SharedObservable;
use http::Method;
use matrix_sdk_base::SendOutsideWasm;
use ruma::api::{
OutgoingRequest, SupportedVersions,
OutgoingRequest, OutgoingRequestExt, SupportedVersions,
auth_scheme::{self, AuthScheme, SendAccessToken},
error::{FromHttpResponseError, IntoHttpError},
path_builder,