1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Inject connection informations in the request extension

This commit is contained in:
Quentin Gliech
2022-10-06 16:30:24 +02:00
parent fc5c8314b5
commit 485778beb3
13 changed files with 530 additions and 15 deletions

View File

@@ -19,13 +19,14 @@ use std::{
};
use anyhow::Context;
use axum::{body::HttpBody, Router};
use axum::{body::HttpBody, Extension, Router};
use listenfd::ListenFd;
use mas_config::{HttpBindConfig, HttpResource, HttpTlsConfig, UnixOrTcp};
use mas_handlers::AppState;
use mas_listener::unix_or_tcp::UnixOrTcpListener;
use mas_listener::{info::Connection, unix_or_tcp::UnixOrTcpListener};
use mas_router::Route;
use rustls::ServerConfig;
use tokio::sync::OnceCell;
#[allow(clippy::trait_duplication_in_bounds)]
pub fn build_router<B>(state: &Arc<AppState>, resources: &[HttpResource]) -> Router<AppState, B>
@@ -60,6 +61,16 @@ where
mas_config::HttpResource::Compat => {
router.merge(mas_handlers::compat_router(state.clone()))
}
// TODO: do a better handler here
mas_config::HttpResource::ConnectionInfo => router.route(
"/connection-info",
axum::routing::get(
|connection: Extension<Arc<OnceCell<Connection>>>| async move {
let connection = connection.get().unwrap();
format!("{connection:?}")
},
),
),
}
}