remove path casing normalization middleware
This commit is contained in:
parent
9f13218c30
commit
bbf76dce01
4 changed files with 15 additions and 46 deletions
|
|
@ -1,12 +1,5 @@
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use axum::{
|
use axum::http::{HeaderValue, header::CONTENT_SECURITY_POLICY};
|
||||||
ServiceExt,
|
|
||||||
extract::Request,
|
|
||||||
http::{HeaderValue, header::CONTENT_SECURITY_POLICY},
|
|
||||||
middleware::map_request,
|
|
||||||
};
|
|
||||||
use chrono::{TimeDelta, Utc};
|
use chrono::{TimeDelta, Utc};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
@ -15,7 +8,7 @@ use tower_http::{
|
||||||
compression::CompressionLayer, set_header::response::SetResponseHeaderLayer, trace::TraceLayer,
|
compression::CompressionLayer, set_header::response::SetResponseHeaderLayer, trace::TraceLayer,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{app::App, middleware::lowercase_uri_path, routes::new_router, worker::run_worker};
|
use crate::{app::App, routes::new_router, worker::run_worker};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
|
|
@ -37,20 +30,18 @@ pub enum Commands {
|
||||||
Serve,
|
Serve,
|
||||||
/// Run background worker
|
/// Run background worker
|
||||||
Worker(WorkerArgs),
|
Worker(WorkerArgs),
|
||||||
// TODO: add a low-frequency worker task exclusively for self-healing
|
|
||||||
// mechanisms like Governor::reset_all()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn serve_command(state: App) -> Result<()> {
|
pub async fn serve_command(state: App) -> Result<()> {
|
||||||
let router = ServiceBuilder::new()
|
let router = new_router(state.clone()).layer(
|
||||||
.layer(map_request(lowercase_uri_path))
|
ServiceBuilder::new()
|
||||||
.layer(TraceLayer::new_for_http())
|
.layer(TraceLayer::new_for_http())
|
||||||
.layer(CompressionLayer::new())
|
.layer(CompressionLayer::new())
|
||||||
.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'"),
|
||||||
))
|
)),
|
||||||
.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))
|
||||||
|
|
@ -63,12 +54,9 @@ pub async fn serve_command(state: App) -> Result<()> {
|
||||||
state.settings.root_path
|
state.settings.root_path
|
||||||
);
|
);
|
||||||
|
|
||||||
axum::serve(
|
axum::serve(listener, router).await?;
|
||||||
listener,
|
|
||||||
ServiceExt::<Request>::into_make_service_with_connect_info::<SocketAddr>(router),
|
Ok(())
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn worker_command(args: &WorkerArgs, state: App) -> Result<()> {
|
pub async fn worker_command(args: &WorkerArgs, state: App) -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ mod cli;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod extractors;
|
mod extractors;
|
||||||
mod field_info;
|
mod field_info;
|
||||||
mod middleware;
|
|
||||||
mod navigator;
|
mod navigator;
|
||||||
mod presentation_form;
|
mod presentation_form;
|
||||||
mod roles;
|
mod roles;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
use axum::http::Request;
|
|
||||||
|
|
||||||
/// Pass to axum::middleware::map_request() to transform the entire URI path
|
|
||||||
/// (but not search query) to lowercase.
|
|
||||||
pub async fn lowercase_uri_path<B>(mut request: Request<B>) -> Request<B> {
|
|
||||||
let path = request.uri().path().to_lowercase();
|
|
||||||
let path_and_query = match request.uri().query() {
|
|
||||||
Some(query) => format!("{}?{}", path, query),
|
|
||||||
None => path,
|
|
||||||
};
|
|
||||||
let builder =
|
|
||||||
axum::http::uri::Builder::from(request.uri().clone()).path_and_query(path_and_query);
|
|
||||||
*request.uri_mut() = builder
|
|
||||||
.build()
|
|
||||||
.expect("lowercasing URI path should not break it");
|
|
||||||
request
|
|
||||||
}
|
|
||||||
|
|
@ -19,8 +19,7 @@ use tower_http::{
|
||||||
set_header::SetResponseHeaderLayer,
|
set_header::SetResponseHeaderLayer,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::auth;
|
use crate::{app::App, auth, settings::Settings};
|
||||||
use crate::{app::App, settings::Settings};
|
|
||||||
|
|
||||||
mod forms;
|
mod forms;
|
||||||
mod relations_single;
|
mod relations_single;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue