1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Remove the ServerLayer from mas-http

This commit is contained in:
Quentin Gliech
2022-11-23 13:51:17 +01:00
parent 4227fa7a83
commit e8c8d0bf8a
7 changed files with 37 additions and 91 deletions

View File

@ -24,7 +24,7 @@ serde_json = "1.0.89"
serde_yaml = "0.9.14"
tokio = { version = "1.22.0", features = ["full"] }
tower = { version = "0.4.13", features = ["full"] }
tower-http = { version = "0.3.5", features = ["fs"] }
tower-http = { version = "0.3.5", features = ["fs", "compression-full"] }
url = "2.3.1"
watchman_client = "0.8.0"

View File

@ -21,7 +21,6 @@ use itertools::Itertools;
use mas_config::RootConfig;
use mas_email::Mailer;
use mas_handlers::{AppState, HttpClientFactory, MatrixHomeserver};
use mas_http::ServerLayer;
use mas_listener::{server::Server, shutdown::ShutdownStream};
use mas_policy::PolicyFactory;
use mas_router::UrlBuilder;
@ -29,7 +28,6 @@ use mas_storage::MIGRATOR;
use mas_tasks::TaskQueue;
use mas_templates::Templates;
use tokio::signal::unix::SignalKind;
use tower::Layer;
use tracing::{error, info, log::warn};
#[derive(Parser, Debug, Default)]
@ -220,8 +218,11 @@ impl Options {
};
// and build the router
let router = crate::server::build_router(state.clone(), &config.resources);
let router = ServerLayer::new(config.name.clone()).layer(router);
let router = crate::server::build_router(
state.clone(),
&config.resources,
config.name.as_deref(),
);
// Display some informations about where we'll be serving connections
let is_tls = config.tls.is_some();

View File

@ -24,16 +24,22 @@ use hyper::StatusCode;
use listenfd::ListenFd;
use mas_config::{HttpBindConfig, HttpResource, HttpTlsConfig, UnixOrTcp};
use mas_handlers::AppState;
use mas_http::otel::TraceLayer;
use mas_listener::{unix_or_tcp::UnixOrTcpListener, ConnectionInfo};
use mas_router::Route;
use mas_spa::ViteManifestService;
use mas_templates::Templates;
use opentelemetry::KeyValue;
use rustls::ServerConfig;
use tower::Layer;
use tower_http::services::ServeDir;
use tower_http::{compression::CompressionLayer, services::ServeDir};
#[allow(clippy::trait_duplication_in_bounds)]
pub fn build_router<B>(state: AppState, resources: &[HttpResource]) -> Router<(), B>
pub fn build_router<B>(
state: AppState,
resources: &[HttpResource],
name: Option<&str>,
) -> Router<(), B>
where
B: HttpBody + Send + 'static,
<B as HttpBody>::Data: Into<axum::body::Bytes> + Send,
@ -106,7 +112,16 @@ where
}
}
router.with_state(state)
let mut trace_layer = TraceLayer::axum();
if let Some(name) = name {
trace_layer = trace_layer.with_static_attribute(KeyValue::new("listener", name.to_owned()));
}
router
.layer(trace_layer)
.layer(CompressionLayer::new())
.with_state(state)
}
pub fn build_tls_server_config(config: &HttpTlsConfig) -> Result<ServerConfig, anyhow::Error> {