Skip to content

Commit 420b8da

Browse files
committed
Replace all the manual HTTP clients with reqwest
1 parent 4c1271a commit 420b8da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+381
-2542
lines changed

Cargo.lock

Lines changed: 8 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ features = [
221221
[workspace.dependencies.sentry]
222222
version = "0.34.0"
223223
default-features = false
224-
features = ["backtrace", "contexts", "panic", "tower"]
224+
features = ["backtrace", "contexts", "panic", "tower", "reqwest"]
225225

226226
# Sentry tower layer
227227
[workspace.dependencies.sentry-tower]
@@ -273,12 +273,12 @@ features = ["rt"]
273273
# Tower services
274274
[workspace.dependencies.tower]
275275
version = "0.5.1"
276-
features = ["util", "limit"]
276+
features = ["util"]
277277

278278
# Tower HTTP layers
279279
[workspace.dependencies.tower-http]
280280
version = "0.6.1"
281-
features = ["cors", "fs", "add-extension", "set-header", "follow-redirect"]
281+
features = ["cors", "fs", "add-extension", "set-header"]
282282

283283
# Logging and tracing
284284
[workspace.dependencies.tracing]
@@ -292,7 +292,7 @@ version = "0.24.0"
292292
features = ["trace", "metrics"]
293293
[workspace.dependencies.opentelemetry-http]
294294
version = "0.13.0"
295-
features = ["hyper"]
295+
features = ["reqwest"]
296296
[workspace.dependencies.opentelemetry-semantic-conventions]
297297
version = "0.16.0"
298298
[workspace.dependencies.tracing-opentelemetry]

crates/axum-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ hyper-util.workspace = true
2727
icu_locid = "1.4.0"
2828
mime = "0.3.17"
2929
rand.workspace = true
30+
reqwest.workspace = true
3031
sentry.workspace = true
3132
serde.workspace = true
3233
serde_with = "3.11.0"

crates/axum-utils/src/client_authorization.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use axum_extra::typed_header::{TypedHeader, TypedHeaderRejectionReason};
1919
use headers::{authorization::Basic, Authorization};
2020
use http::{Request, StatusCode};
2121
use mas_data_model::{Client, JwksOrJwksUri};
22-
use mas_http::HttpServiceExt;
22+
use mas_http::RequestBuilderExt;
2323
use mas_iana::oauth::OAuthClientAuthenticationMethod;
2424
use mas_jose::{jwk::PublicJsonWebKeySet, jwt::Jwt};
2525
use mas_keystore::Encrypter;
@@ -28,9 +28,6 @@ use oauth2_types::errors::{ClientError, ClientErrorCode};
2828
use serde::{de::DeserializeOwned, Deserialize};
2929
use serde_json::Value;
3030
use thiserror::Error;
31-
use tower::{Service, ServiceExt};
32-
33-
use crate::http_client_factory::HttpClientFactory;
3431

3532
static JWT_BEARER_CLIENT_ASSERTION: &str = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
3633

@@ -104,7 +101,7 @@ impl Credentials {
104101
#[tracing::instrument(skip_all, err)]
105102
pub async fn verify(
106103
&self,
107-
http_client_factory: &HttpClientFactory,
104+
http_client: &reqwest::Client,
108105
encrypter: &Encrypter,
109106
method: &OAuthClientAuthenticationMethod,
110107
client: &Client,
@@ -146,7 +143,7 @@ impl Credentials {
146143
.as_ref()
147144
.ok_or(CredentialsVerificationError::InvalidClientConfig)?;
148145

149-
let jwks = fetch_jwks(http_client_factory, jwks)
146+
let jwks = fetch_jwks(http_client, jwks)
150147
.await
151148
.map_err(|_| CredentialsVerificationError::JwksFetchFailed)?;
152149

@@ -181,27 +178,22 @@ impl Credentials {
181178
}
182179

183180
async fn fetch_jwks(
184-
http_client_factory: &HttpClientFactory,
181+
http_client: &reqwest::Client,
185182
jwks: &JwksOrJwksUri,
186183
) -> Result<PublicJsonWebKeySet, BoxError> {
187184
let uri = match jwks {
188185
JwksOrJwksUri::Jwks(j) => return Ok(j.clone()),
189186
JwksOrJwksUri::JwksUri(u) => u,
190187
};
191188

192-
let request = http::Request::builder()
193-
.uri(uri.as_str())
194-
.body(mas_http::EmptyBody::new())
195-
.unwrap();
196-
197-
let mut client = http_client_factory
198-
.client("client.fetch_jwks")
199-
.response_body_to_bytes()
200-
.json_response::<PublicJsonWebKeySet>();
201-
202-
let response = client.ready().await?.call(request).await?;
189+
let response = http_client
190+
.get(uri.as_str())
191+
.send_traced()
192+
.await?
193+
.json()
194+
.await?;
203195

204-
Ok(response.into_body())
196+
Ok(response)
205197
}
206198

207199
#[derive(Debug, Error)]

crates/axum-utils/src/http_client_factory.rs

Lines changed: 0 additions & 65 deletions
This file was deleted.

crates/axum-utils/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub mod cookies;
1212
pub mod csrf;
1313
pub mod error_wrapper;
1414
pub mod fancy_error;
15-
pub mod http_client_factory;
1615
pub mod jwt;
1716
pub mod language_detection;
1817
pub mod sentry;

crates/cli/src/app_state.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ipnetwork::IpNetwork;
1414
use mas_data_model::SiteConfig;
1515
use mas_handlers::{
1616
passwords::PasswordManager, ActivityTracker, BoundActivityTracker, CookieManager, ErrorWrapper,
17-
GraphQLSchema, HttpClientFactory, Limiter, MetadataCache, RequesterFingerprint,
17+
GraphQLSchema, Limiter, MetadataCache, RequesterFingerprint,
1818
};
1919
use mas_i18n::Translator;
2020
use mas_keystore::{Encrypter, Keystore};
@@ -43,7 +43,6 @@ pub struct AppState {
4343
pub homeserver_connection: SynapseConnection,
4444
pub policy_factory: Arc<PolicyFactory>,
4545
pub graphql_schema: GraphQLSchema,
46-
pub http_client_factory: HttpClientFactory,
4746
pub http_client: reqwest::Client,
4847
pub password_manager: PasswordManager,
4948
pub metadata_cache: MetadataCache,
@@ -170,12 +169,6 @@ impl FromRef<AppState> for UrlBuilder {
170169
}
171170
}
172171

173-
impl FromRef<AppState> for HttpClientFactory {
174-
fn from_ref(input: &AppState) -> Self {
175-
input.http_client_factory.clone()
176-
}
177-
}
178-
179172
impl FromRef<AppState> for reqwest::Client {
180173
fn from_ref(input: &AppState) -> Self {
181174
input.http_client.clone()

0 commit comments

Comments
 (0)