fix uri normalization bug
This commit is contained in:
parent
02166b2d61
commit
e5215613d5
1 changed files with 15 additions and 12 deletions
27
src/cli.rs
27
src/cli.rs
|
@ -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(SetResponseHeaderLayer::if_not_present(
|
||||||
.layer(NormalizePathLayer::trim_trailing_slash())
|
CONTENT_SECURITY_POLICY,
|
||||||
.layer(SetResponseHeaderLayer::if_not_present(
|
HeaderValue::from_static("frame-ancestors 'none'"),
|
||||||
CONTENT_SECURITY_POLICY,
|
))
|
||||||
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<()> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue