Skip to content

Commit 4c1271a

Browse files
committed
Replace HTTP client in oidc-client with reqwest
1 parent 366fb1d commit 4c1271a

Some content is hidden

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

41 files changed

+203
-1941
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@ features = ["rt"]
273273
# Tower services
274274
[workspace.dependencies.tower]
275275
version = "0.5.1"
276-
features = ["util"]
276+
features = ["util", "limit"]
277277

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

283283
# Logging and tracing
284284
[workspace.dependencies.tracing]

clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ disallowed-methods = [
55
{ path = "chrono::Utc::now", reason = "source the current time from the clock instead" },
66
{ path = "ulid::Ulid::from_datetime", reason = "use Ulid::from_datetime_with_source instead" },
77
{ path = "ulid::Ulid::new", reason = "use Ulid::from_datetime_with_source instead" },
8+
{ path = "reqwest::Client::new", reason = "use mas_http::reqwest_client instead" },
9+
{ path = "reqwest::RequestBuilder::send", reason = "use send_traced instead" },
810
]
911

1012
disallowed-types = [

crates/axum-utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ulid.workspace = true
4141

4242
oauth2-types.workspace = true
4343
mas-data-model.workspace = true
44-
mas-http = { workspace = true, features = ["client"] }
44+
mas-http.workspace = true
4545
mas-iana.workspace = true
4646
mas-jose.workspace = true
4747
mas-keystore.workspace = true

crates/cli/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ itertools = "0.13.0"
3131
listenfd = "1.0.1"
3232
rand.workspace = true
3333
rand_chacha = "0.3.1"
34+
reqwest.workspace = true
3435
rustls.workspace = true
3536
serde_json.workspace = true
3637
serde_yaml = "0.9.34"
@@ -71,8 +72,8 @@ sentry-tower.workspace = true
7172
mas-config.workspace = true
7273
mas-data-model.workspace = true
7374
mas-email.workspace = true
74-
mas-handlers = { workspace = true }
75-
mas-http = { workspace = true, features = ["client"] }
75+
mas-handlers.workspace = true
76+
mas-http.workspace = true
7677
mas-i18n.workspace = true
7778
mas-iana.workspace = true
7879
mas-keystore.workspace = true

crates/cli/src/app_state.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct AppState {
4444
pub policy_factory: Arc<PolicyFactory>,
4545
pub graphql_schema: GraphQLSchema,
4646
pub http_client_factory: HttpClientFactory,
47+
pub http_client: reqwest::Client,
4748
pub password_manager: PasswordManager,
4849
pub metadata_cache: MetadataCache,
4950
pub site_config: SiteConfig,
@@ -116,13 +117,9 @@ impl AppState {
116117

117118
let mut repo = PgRepository::from_conn(conn);
118119

119-
let http_service = self
120-
.http_client_factory
121-
.http_service("upstream_oauth2.metadata");
122-
123120
self.metadata_cache
124121
.warm_up_and_run(
125-
http_service,
122+
&self.http_client,
126123
std::time::Duration::from_secs(60 * 15),
127124
&mut repo,
128125
)
@@ -179,6 +176,12 @@ impl FromRef<AppState> for HttpClientFactory {
179176
}
180177
}
181178

179+
impl FromRef<AppState> for reqwest::Client {
180+
fn from_ref(input: &AppState) -> Self {
181+
input.http_client.clone()
182+
}
183+
}
184+
182185
impl FromRef<AppState> for PasswordManager {
183186
fn from_ref(input: &AppState) -> Self {
184187
input.password_manager.clone()

crates/cli/src/commands/server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl Options {
150150

151151
let http_client_factory = HttpClientFactory::new();
152152

153+
let http_client = mas_http::reqwest_client();
154+
153155
let homeserver_connection = SynapseConnection::new(
154156
config.matrix.homeserver.clone(),
155157
config.matrix.endpoint.clone(),
@@ -242,6 +244,7 @@ impl Options {
242244
policy_factory,
243245
graphql_schema,
244246
http_client_factory,
247+
http_client,
245248
password_manager,
246249
metadata_cache,
247250
site_config,

crates/handlers/src/upstream_oauth2/authorize.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use axum::{
99
response::{IntoResponse, Redirect},
1010
};
1111
use hyper::StatusCode;
12-
use mas_axum_utils::{
13-
cookies::CookieJar, http_client_factory::HttpClientFactory, sentry::SentryEventID,
14-
};
12+
use mas_axum_utils::{cookies::CookieJar, sentry::SentryEventID};
1513
use mas_data_model::UpstreamOAuthProvider;
1614
use mas_oidc_client::requests::authorization_code::AuthorizationRequestData;
1715
use mas_router::UrlBuilder;

crates/handlers/src/upstream_oauth2/callback.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use axum::{
99
response::IntoResponse,
1010
};
1111
use hyper::StatusCode;
12-
use mas_axum_utils::{
13-
cookies::CookieJar, http_client_factory::HttpClientFactory, sentry::SentryEventID,
14-
};
12+
use mas_axum_utils::{cookies::CookieJar, sentry::SentryEventID};
1513
use mas_data_model::UpstreamOAuthProvider;
1614
use mas_keystore::{Encrypter, Keystore};
1715
use mas_oidc_client::requests::{
@@ -128,7 +126,6 @@ impl IntoResponse for RouteError {
128126
pub(crate) async fn get(
129127
mut rng: BoxRng,
130128
clock: BoxClock,
131-
State(http_client_factory): State<HttpClientFactory>,
132129
State(metadata_cache): State<MetadataCache>,
133130
mut repo: BoxRepository,
134131
State(url_builder): State<UrlBuilder>,

crates/http/Cargo.toml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ http-body.workspace = true
2121
http-body-util.workspace = true
2222
hyper.workspace = true
2323
hyper-util.workspace = true
24-
hyper-rustls = { workspace = true, optional = true }
24+
hyper-rustls.workspace = true
2525
opentelemetry.workspace = true
2626
opentelemetry-http.workspace = true
2727
opentelemetry-semantic-conventions.workspace = true
28-
rustls = { workspace = true, optional = true }
29-
rustls-platform-verifier = { workspace = true, optional = true }
28+
rustls.workspace = true
29+
rustls-platform-verifier.workspace = true
3030
pin-project-lite = "0.2.14"
3131
reqwest.workspace = true
3232
serde.workspace = true
@@ -38,20 +38,8 @@ tower-http.workspace = true
3838
tracing.workspace = true
3939
tracing-opentelemetry.workspace = true
4040

41-
mas-tower = { workspace = true, optional = true }
41+
mas-tower.workspace = true
4242

4343
[dev-dependencies]
4444
anyhow.workspace = true
4545
tokio.workspace = true
46-
47-
[features]
48-
client = [
49-
"dep:mas-tower",
50-
"dep:rustls",
51-
"dep:hyper-rustls",
52-
"dep:rustls-platform-verifier",
53-
"tower/limit",
54-
"tower-http/timeout",
55-
"tower-http/follow-redirect",
56-
"tower-http/set-header",
57-
]

0 commit comments

Comments
 (0)