diff --git a/src/api/client_server/keys.rs b/src/api/client_server/keys.rs index 7909767d..b30a91eb 100644 --- a/src/api/client_server/keys.rs +++ b/src/api/client_server/keys.rs @@ -75,24 +75,20 @@ pub(crate) async fn upload_keys_route(body: Ruma) -> R pub(crate) async fn get_keys_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let response = get_keys_helper( + get_keys_helper( Some(sender_user), &body.device_keys, |u| u == sender_user, true, // Always allow local users to see device names of other local users ) - .await?; - - Ok(response) + .await } /// # `POST /_matrix/client/r0/keys/claim` /// /// Claims one-time keys pub(crate) async fn claim_keys_route(body: Ruma) -> Result { - let response = claim_keys_helper(&body.one_time_keys).await?; - - Ok(response) + claim_keys_helper(&body.one_time_keys).await } /// # `POST /_matrix/client/r0/keys/device_signing/upload` @@ -262,8 +258,6 @@ pub(crate) async fn get_keys_helper bool>( let mut get_over_federation = HashMap::new(); for (user_id, device_ids) in device_keys_input { - let user_id: &UserId = user_id; - if !user_is_local(user_id) { get_over_federation .entry(user_id.server_name()) @@ -322,7 +316,7 @@ pub(crate) async fn get_keys_helper bool>( { self_signing_keys.insert(user_id.to_owned(), self_signing_key); } - if Some(user_id) == sender_user { + if user_id == sender_user.expect("user is authenticated") { if let Some(user_signing_key) = services().users.get_user_signing_key(user_id)? { user_signing_keys.insert(user_id.to_owned(), user_signing_key); } diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index 9f4c45b1..1ba1c6be 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -27,6 +27,8 @@ const MXC_LENGTH: usize = 32; /// Cache control for immutable objects const CACHE_CONTROL_IMMUTABLE: &str = "public, max-age=31536000, immutable"; +const CORP_CROSS_ORIGIN: &str = "cross-origin"; + /// # `GET /_matrix/media/v3/config` /// /// Returns max upload size. @@ -180,7 +182,7 @@ pub(crate) async fn get_content_route(body: Ruma) -> R file, content_type, content_disposition, - cross_origin_resource_policy: Some("cross-origin".to_owned()), + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) } else if !server_is_ours(&body.server_name) && body.allow_remote { @@ -242,7 +244,7 @@ pub(crate) async fn get_content_as_filename_route( file, content_type, content_disposition: Some(format!("inline; filename={}", body.filename)), - cross_origin_resource_policy: Some("cross-origin".to_owned()), + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) } else if !server_is_ours(&body.server_name) && body.allow_remote { @@ -259,7 +261,7 @@ pub(crate) async fn get_content_as_filename_route( content_disposition: Some(format!("inline: filename={}", body.filename)), content_type: remote_content_response.content_type, file: remote_content_response.file, - cross_origin_resource_policy: Some("cross-origin".to_owned()), + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }), Err(e) => { @@ -323,7 +325,7 @@ pub(crate) async fn get_content_thumbnail_route( Ok(get_content_thumbnail::v3::Response { file, content_type, - cross_origin_resource_policy: Some("cross-origin".to_owned()), + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) } else if !server_is_ours(&body.server_name) && body.allow_remote { @@ -409,7 +411,7 @@ async fn get_remote_content( { // we'll lie to the client and say the blocked server's media was not found and // log. the client has no way of telling anyways so this is a security bonus. - debug_warn!("Received request for media `{}` on blocklisted server", mxc); + debug_warn!("Received request for media `{mxc}` on blocklisted server"); return Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")); }