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 axum::{
|
||||
ServiceExt,
|
||||
extract::Request,
|
||||
http::{HeaderValue, header::CONTENT_SECURITY_POLICY},
|
||||
middleware::map_request,
|
||||
};
|
||||
use axum::http::{HeaderValue, header::CONTENT_SECURITY_POLICY};
|
||||
use chrono::{TimeDelta, Utc};
|
||||
use clap::{Parser, Subcommand};
|
||||
use tokio::time::sleep;
|
||||
|
|
@ -15,7 +8,7 @@ use tower_http::{
|
|||
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)]
|
||||
#[command(version, about, long_about = None)]
|
||||
|
|
@ -37,20 +30,18 @@ pub enum Commands {
|
|||
Serve,
|
||||
/// Run background worker
|
||||
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<()> {
|
||||
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'"),
|
||||
))
|
||||
.service(new_router(state.clone()));
|
||||
let router = new_router(state.clone()).layer(
|
||||
ServiceBuilder::new()
|
||||
.layer(TraceLayer::new_for_http())
|
||||
.layer(CompressionLayer::new())
|
||||
.layer(SetResponseHeaderLayer::if_not_present(
|
||||
CONTENT_SECURITY_POLICY,
|
||||
HeaderValue::from_static("frame-ancestors 'none'"),
|
||||
)),
|
||||
);
|
||||
|
||||
let listener =
|
||||
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
|
||||
);
|
||||
|
||||
axum::serve(
|
||||
listener,
|
||||
ServiceExt::<Request>::into_make_service_with_connect_info::<SocketAddr>(router),
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
axum::serve(listener, router).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn worker_command(args: &WorkerArgs, state: App) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ mod cli;
|
|||
mod errors;
|
||||
mod extractors;
|
||||
mod field_info;
|
||||
mod middleware;
|
||||
mod navigator;
|
||||
mod presentation_form;
|
||||
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,
|
||||
};
|
||||
|
||||
use crate::auth;
|
||||
use crate::{app::App, settings::Settings};
|
||||
use crate::{app::App, auth, settings::Settings};
|
||||
|
||||
mod forms;
|
||||
mod relations_single;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue