You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Add a global HTTP client factory
This commit is contained in:
@ -16,6 +16,7 @@ use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use hyper::{Response, Uri};
|
||||
use mas_config::PolicyConfig;
|
||||
use mas_handlers::HttpClientFactory;
|
||||
use mas_http::HttpServiceExt;
|
||||
use mas_policy::PolicyFactory;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
@ -66,13 +67,14 @@ 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);
|
||||
match &self.subcommand {
|
||||
SC::Http {
|
||||
show_headers,
|
||||
json: false,
|
||||
url,
|
||||
} => {
|
||||
let mut client = mas_http::client("cli-debug-http").await?;
|
||||
let mut client = http_client_factory.client("cli-debug-http").await?;
|
||||
let request = hyper::Request::builder()
|
||||
.uri(url)
|
||||
.body(hyper::Body::empty())?;
|
||||
@ -96,7 +98,8 @@ impl Options {
|
||||
json: true,
|
||||
url,
|
||||
} => {
|
||||
let mut client = mas_http::client("cli-debug-http")
|
||||
let mut client = http_client_factory
|
||||
.client("cli-debug-http")
|
||||
.await?
|
||||
.response_body_to_bytes()
|
||||
.json_response();
|
||||
|
@ -20,7 +20,7 @@ use futures_util::stream::{StreamExt, TryStreamExt};
|
||||
use itertools::Itertools;
|
||||
use mas_config::RootConfig;
|
||||
use mas_email::Mailer;
|
||||
use mas_handlers::{AppState, MatrixHomeserver};
|
||||
use mas_handlers::{AppState, HttpClientFactory, MatrixHomeserver};
|
||||
use mas_http::ServerLayer;
|
||||
use mas_listener::{server::Server, shutdown::ShutdownStream};
|
||||
use mas_policy::PolicyFactory;
|
||||
@ -187,6 +187,9 @@ impl Options {
|
||||
|
||||
let graphql_schema = mas_handlers::graphql_schema(&pool);
|
||||
|
||||
// Maximum 50 outgoing HTTP requests at a time
|
||||
let http_client_factory = HttpClientFactory::new(50);
|
||||
|
||||
let state = AppState {
|
||||
pool,
|
||||
templates,
|
||||
@ -197,6 +200,7 @@ impl Options {
|
||||
homeserver,
|
||||
policy_factory,
|
||||
graphql_schema,
|
||||
http_client_factory,
|
||||
};
|
||||
|
||||
let mut fd_manager = listenfd::ListenFd::from_env();
|
||||
|
Reference in New Issue
Block a user