1
0
Fork 0
forked from 2sys/shoutdotdev

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 axum::{
extract::Request,
http::{header::CONTENT_SECURITY_POLICY, HeaderValue},
middleware::map_request,
ServiceExt,
};
use chrono::{TimeDelta, Utc};
use clap::{Parser, Subcommand};
@ -41,17 +43,16 @@ pub enum Commands {
}
pub async fn serve_command(state: AppState) -> Result<()> {
let router = new_router(state.clone()).layer(
ServiceBuilder::new()
.layer(map_request(lowercase_uri_path))
.layer(TraceLayer::new_for_http())
.layer(CompressionLayer::new())
.layer(NormalizePathLayer::trim_trailing_slash())
.layer(SetResponseHeaderLayer::if_not_present(
CONTENT_SECURITY_POLICY,
HeaderValue::from_static("frame-ancestors 'none'"),
)),
);
let router = ServiceBuilder::new()
.layer(map_request(lowercase_uri_path))
.layer(TraceLayer::new_for_http())
.layer(CompressionLayer::new())
.layer(SetResponseHeaderLayer::if_not_present(
CONTENT_SECURITY_POLICY,
HeaderValue::from_static("frame-ancestors 'none'"),
))
.layer(NormalizePathLayer::trim_trailing_slash())
.service(new_router(state.clone()));
let listener =
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
);
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<()> {