You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
Make the HTTP client factory reuse the underlying client
This avoids duplicating clients, and makes it so that they all share the same connection pool.
This commit is contained in:
@@ -67,7 +67,7 @@ impl Options {
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn run(self, root: &super::Options) -> anyhow::Result<()> {
|
||||
use Subcommand as SC;
|
||||
let http_client_factory = HttpClientFactory::new(10);
|
||||
let http_client_factory = HttpClientFactory::new().await?;
|
||||
match self.subcommand {
|
||||
SC::Http {
|
||||
show_headers,
|
||||
@@ -75,7 +75,7 @@ impl Options {
|
||||
url,
|
||||
} => {
|
||||
let _span = info_span!("cli.debug.http").entered();
|
||||
let mut client = http_client_factory.client().await?;
|
||||
let mut client = http_client_factory.client("debug");
|
||||
let request = hyper::Request::builder()
|
||||
.uri(url)
|
||||
.body(hyper::Body::empty())?;
|
||||
@@ -99,8 +99,7 @@ impl Options {
|
||||
} => {
|
||||
let _span = info_span!("cli.debug.http").entered();
|
||||
let mut client = http_client_factory
|
||||
.client()
|
||||
.await?
|
||||
.client("debug")
|
||||
.response_body_to_bytes()
|
||||
.json_response();
|
||||
let request = hyper::Request::builder()
|
||||
|
@@ -97,6 +97,8 @@ impl Options {
|
||||
// Load and compile the templates
|
||||
let templates = templates_from_config(&config.templates, &url_builder).await?;
|
||||
|
||||
let http_client_factory = HttpClientFactory::new().await?;
|
||||
|
||||
if !self.no_worker {
|
||||
let mailer = mailer_from_config(&config.email, &templates)?;
|
||||
mailer.test_connection().await?;
|
||||
@@ -105,15 +107,12 @@ impl Options {
|
||||
let mut rng = thread_rng();
|
||||
let worker_name = Alphanumeric.sample_string(&mut rng, 10);
|
||||
|
||||
// Maximum 50 outgoing HTTP requests at a time
|
||||
let http_client_factory = HttpClientFactory::new(50);
|
||||
|
||||
info!(worker_name, "Starting task worker");
|
||||
let conn = SynapseConnection::new(
|
||||
config.matrix.homeserver.clone(),
|
||||
config.matrix.endpoint.clone(),
|
||||
config.matrix.secret.clone(),
|
||||
http_client_factory,
|
||||
http_client_factory.clone(),
|
||||
);
|
||||
let monitor = mas_tasks::init(&worker_name, &pool, &mailer, conn).await?;
|
||||
// TODO: grab the handle
|
||||
@@ -126,9 +125,6 @@ impl Options {
|
||||
|
||||
let password_manager = password_manager_from_config(&config.passwords).await?;
|
||||
|
||||
// Maximum 50 outgoing HTTP requests at a time
|
||||
let http_client_factory = HttpClientFactory::new(50);
|
||||
|
||||
// The upstream OIDC metadata cache
|
||||
let metadata_cache = MetadataCache::new();
|
||||
|
||||
|
@@ -49,7 +49,7 @@ impl Options {
|
||||
let mailer = mailer_from_config(&config.email, &templates)?;
|
||||
mailer.test_connection().await?;
|
||||
|
||||
let http_client_factory = HttpClientFactory::new(50);
|
||||
let http_client_factory = HttpClientFactory::new().await?;
|
||||
let conn = SynapseConnection::new(
|
||||
config.matrix.homeserver.clone(),
|
||||
config.matrix.endpoint.clone(),
|
||||
|
Reference in New Issue
Block a user