Merge branch 'master' into crypto-improvements

master
Damir Jelić 2020-10-01 12:21:45 +02:00
commit bcdcdeb259
6 changed files with 24 additions and 15 deletions

View File

@ -1,4 +1,4 @@
#![type_length_limit = "1700984"]
#![type_length_limit = "1702124"]
use matrix_sdk::{
api::r0::sync::sync_events::Response as SyncResponse,

View File

@ -727,11 +727,12 @@ impl Client {
/// # Examples
/// ```no_run
/// use matrix_sdk::Client;
/// # use std::convert::TryInto;
/// # use url::Url;
/// # let homeserver = Url::parse("http://example.com").unwrap();
/// # let limit = Some(10);
/// # let since = Some("since token");
/// # let server = Some("server name");
/// # let server = Some("servername.com".try_into().unwrap());
///
/// let mut client = Client::new(homeserver).unwrap();
/// # use futures::executor::block_on;
@ -744,7 +745,7 @@ impl Client {
&self,
limit: Option<u32>,
since: Option<&str>,
server: Option<&str>,
server: Option<&ServerName>,
) -> Result<get_public_rooms::Response> {
let limit = limit.map(|n| UInt::try_from(n).ok()).flatten();

View File

@ -37,6 +37,10 @@ pub enum Error {
#[error("the queried endpoint requires authentication but was called before logging in")]
AuthenticationRequired,
/// Queried endpoint is not meant for clients.
#[error("the queried endpoint is not meant for clients")]
NotClientRequest,
/// An error at the HTTP layer.
#[error(transparent)]
Reqwest(#[from] ReqwestError),

View File

@ -19,7 +19,9 @@ use reqwest::{Client, Response};
use tracing::trace;
use url::Url;
use matrix_sdk_common::{api::r0::media::create_content, locks::RwLock, FromHttpResponseError};
use matrix_sdk_common::{
api::r0::media::create_content, locks::RwLock, AuthScheme, FromHttpResponseError,
};
use matrix_sdk_common_macros::async_trait;
use crate::{ClientConfig, Error, OutgoingRequest, Result, Session};
@ -91,16 +93,18 @@ impl HttpClient {
) -> Result<http::Response<Vec<u8>>> {
let mut request = {
let read_guard;
let access_token = if Request::METADATA.requires_authentication {
read_guard = session.read().await;
let access_token = match Request::METADATA.authentication {
AuthScheme::AccessToken => {
read_guard = session.read().await;
if let Some(session) = read_guard.as_ref() {
Some(session.access_token.as_str())
} else {
return Err(Error::AuthenticationRequired);
if let Some(session) = read_guard.as_ref() {
Some(session.access_token.as_str())
} else {
return Err(Error::AuthenticationRequired);
}
}
} else {
None
AuthScheme::None => None,
_ => return Err(Error::NotClientRequest),
};
request.try_into_http_request(&self.homeserver.to_string(), access_token)?

View File

@ -21,7 +21,7 @@ js_int = "0.1.9"
[dependencies.ruma]
version = "0.0.1"
git = "https://github.com/ruma/ruma"
rev = "4a9b1aeb3c87bd8574391d7084ec5bf109f7d363"
rev = "3869d75837b7aab60eef58fc834e498317d1e4a4"
features = ["client-api", "unstable-pre-spec", "unstable-exhaustive-types"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View File

@ -5,9 +5,9 @@ pub use ruma::{
api::{
client as api,
error::{FromHttpRequestError, FromHttpResponseError, IntoHttpError, ServerError},
EndpointError, Outgoing, OutgoingRequest,
AuthScheme, EndpointError, OutgoingRequest,
},
directory, encryption, events, identifiers, presence, push, thirdparty, Raw,
directory, encryption, events, identifiers, presence, push, thirdparty, Outgoing, Raw,
};
pub use uuid;