fix uri normalization bug

This commit is contained in:
Brent Schroeter 2025-04-12 23:38:35 -07:00
parent 02166b2d61
commit e5215613d5

View file

@ -1,7 +1,9 @@
use anyhow::Result; use anyhow::Result;
use axum::{ use axum::{
extract::Request,
http::{header::CONTENT_SECURITY_POLICY, HeaderValue}, http::{header::CONTENT_SECURITY_POLICY, HeaderValue},
middleware::map_request, middleware::map_request,
ServiceExt,
}; };
use chrono::{TimeDelta, Utc}; use chrono::{TimeDelta, Utc};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
@ -41,17 +43,16 @@ pub enum Commands {
} }
pub async fn serve_command(state: AppState) -> Result<()> { pub async fn serve_command(state: AppState) -> Result<()> {
let router = new_router(state.clone()).layer( let router = ServiceBuilder::new()
ServiceBuilder::new()
.layer(map_request(lowercase_uri_path)) .layer(map_request(lowercase_uri_path))
.layer(TraceLayer::new_for_http()) .layer(TraceLayer::new_for_http())
.layer(CompressionLayer::new()) .layer(CompressionLayer::new())
.layer(NormalizePathLayer::trim_trailing_slash())
.layer(SetResponseHeaderLayer::if_not_present( .layer(SetResponseHeaderLayer::if_not_present(
CONTENT_SECURITY_POLICY, CONTENT_SECURITY_POLICY,
HeaderValue::from_static("frame-ancestors 'none'"), HeaderValue::from_static("frame-ancestors 'none'"),
)), ))
); .layer(NormalizePathLayer::trim_trailing_slash())
.service(new_router(state.clone()));
let listener = let listener =
tokio::net::TcpListener::bind((state.settings.host.clone(), state.settings.port)) tokio::net::TcpListener::bind((state.settings.host.clone(), state.settings.port))
@ -64,7 +65,9 @@ pub async fn serve_command(state: AppState) -> Result<()> {
state.settings.base_path state.settings.base_path
); );
axum::serve(listener, router).await.map_err(Into::into) axum::serve(listener, ServiceExt::<Request>::into_make_service(router))
.await
.map_err(Into::into)
} }
pub async fn worker_command(args: &WorkerArgs, state: AppState) -> Result<()> { pub async fn worker_command(args: &WorkerArgs, state: AppState) -> Result<()> {