Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
22b582e
Use a radix trie for route matching
ElijahAhianyo Aug 1, 2026
0f58776
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Aug 1, 2026
6af73da
common_prefix_len can use bytes since in practice routes are ascii based
ElijahAhianyo Aug 1, 2026
6d29052
Merge remote-tracking branch 'origin/elijah/router-trie' into elijah/…
ElijahAhianyo Aug 1, 2026
6b56ed1
Use Matchit crate
ElijahAhianyo Aug 17, 2026
7ee8813
Add tests with lots and lots of improvements!
ElijahAhianyo Aug 17, 2026
8bc1712
Merge branch 'master' into elijah/router-trie
ElijahAhianyo Aug 18, 2026
fb47870
make clippy happy
ElijahAhianyo Aug 18, 2026
0ba361b
doctest fix
ElijahAhianyo Aug 18, 2026
89dc1ee
remove print
ElijahAhianyo Aug 18, 2026
9251215
Merge branch 'master' into elijah/router-trie
ElijahAhianyo Aug 20, 2026
eefac7c
fix tests after merge conflict resolution
ElijahAhianyo Aug 20, 2026
994cbe6
fix UI tests, more improvs
ElijahAhianyo Aug 23, 2026
a176534
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Aug 23, 2026
0a257a7
add more tests
ElijahAhianyo Aug 25, 2026
f5d3214
lint
ElijahAhianyo Aug 25, 2026
189751b
comments
ElijahAhianyo Aug 25, 2026
020cc77
revert snapshot
ElijahAhianyo Aug 25, 2026
9a9c074
Merge branch 'master' into elijah/router-trie
ElijahAhianyo Aug 25, 2026
3d85d8b
clippy fix
ElijahAhianyo Aug 25, 2026
6276759
address most comments
ElijahAhianyo Sep 1, 2026
e0c8d48
Merge branch 'master' into elijah/router-trie
ElijahAhianyo Sep 1, 2026
325191e
merge routers mounted at the same path.
ElijahAhianyo Sep 3, 2026
7f87a5a
clippy fix
ElijahAhianyo Sep 3, 2026
467aab1
Merge branch 'master' into elijah/router-trie
ElijahAhianyo Sep 3, 2026
c00ea46
lint fix
ElijahAhianyo Sep 4, 2026
9f20338
comments and a bit of tests
ElijahAhianyo Sep 4, 2026
5007307
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Sep 4, 2026
ca51afb
cargo fmt
ElijahAhianyo Sep 4, 2026
5169c0f
Merge remote-tracking branch 'origin/elijah/router-trie' into elijah/…
ElijahAhianyo Sep 4, 2026
00a72d3
use unwrap or else
ElijahAhianyo Sep 4, 2026
b4fd96d
use clippy's suggestion
ElijahAhianyo Sep 5, 2026
1bf8811
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Sep 5, 2026
00f502c
lint
ElijahAhianyo Sep 5, 2026
1c311f9
Merge remote-tracking branch 'origin/elijah/router-trie' into elijah/…
ElijahAhianyo Sep 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ insta-cmd = "0.7"
is_terminal_polyfill = "1.70"
lettre = { version = "0.11.22", default-features = false }
libtest-mimic = "0.8"
matchit = "0.9.2"
mime = "0.3"
mime_guess = { version = "2", default-features = false }
mockall = "0.15"
Expand Down
1 change: 1 addition & 0 deletions cot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ idna = { workspace = true, optional = true }
indexmap.workspace = true
is_terminal_polyfill.workspace = true
lettre = { workspace = true, features = ["builder", "sendmail-transport", "smtp-transport", "tokio1", "tokio1-rustls", "ring", "rustls-platform-verifier"], optional = true }
matchit.workspace = true
mime.workspace = true
mime_guess.workspace = true
multer.workspace = true
Expand Down
94 changes: 83 additions & 11 deletions cot/src/error_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tracing::{Level, error, warn};
use crate::config::ProjectConfig;
use crate::error::NotFound;
use crate::router::Router;
use crate::router::path::AbsolutePath;
use crate::{Error, Result, StatusCode, Template};

#[derive(Debug)]
Expand Down Expand Up @@ -123,7 +124,12 @@ impl ErrorPageTemplateBuilder {
fn diagnostics(&mut self, diagnostics: &Diagnostics) -> &mut Self {
self.project_config = format!("{:#?}", diagnostics.project_config);
self.route_data.clear();
Self::build_route_data(&mut self.route_data, &diagnostics.router, "", "");
Self::build_route_data(
&mut self.route_data,
&diagnostics.router,
&AbsolutePath::root(),
"",
);
self.request_data = diagnostics
.request_head
.as_ref()
Expand All @@ -133,14 +139,16 @@ impl ErrorPageTemplateBuilder {

fn build_route_data(
route_data: &mut Vec<RouteData>,
router: &Router,
url_prefix: &str,
router: &Arc<Router>,
url_prefix: &AbsolutePath,
index_prefix: &str,
) {
for (index, route) in router.routes().iter().enumerate() {
let full_path = url_prefix.join(&AbsolutePath::new(route.url()));

route_data.push(RouteData {
index: format!("{index_prefix}{index}"),
path: format!("{url_prefix}{}", route.url()),
path: full_path.to_string(),
kind: match route.kind() {
crate::router::RouteKind::Router => if route_data.is_empty() {
"Root Router"
Expand All @@ -151,13 +159,14 @@ impl ErrorPageTemplateBuilder {
crate::router::RouteKind::Handler => "View".to_owned(),
},
name: route.name().unwrap_or_default().to_owned(),
app: route.app_name().map(|a| a.0.clone()).unwrap_or_default(),
});

if let Some(inner_router) = route.router() {
Self::build_route_data(
route_data,
inner_router,
&format!("{}{}", url_prefix, route.url()),
&inner_router,
&full_path,
&format!("{index_prefix}{index}."),
);
}
Expand Down Expand Up @@ -242,6 +251,7 @@ struct RouteData {
path: String,
kind: String,
name: String,
app: String,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -453,6 +463,10 @@ mod tests {
use std::panic;
use std::sync::Arc;

use cot_core::handler::RequestHandler;
use cot_core::html::Html;
use cot_core::request::Request;
use cot_core::response::{IntoResponse, Response};
use tracing_test::traced_test;

use super::*;
Expand All @@ -468,6 +482,14 @@ mod tests {
}
}

struct MockHandler;

impl RequestHandler for MockHandler {
fn handle(&self, _request: Request) -> impl Future<Output = Result<Response>> {
std::future::ready(Html::new("OK").into_response())
}
}

#[test]
#[traced_test]
fn test_log_error() {
Expand Down Expand Up @@ -588,9 +610,16 @@ mod tests {
let mut route_data = Vec::new();
let sub_sub_router = Router::with_urls(vec![]);
let sub_router = Router::with_urls(vec![Route::with_router("/bar", sub_sub_router)]);
let router = Router::with_urls(vec![Route::with_router("/foo", sub_router)]);

ErrorPageTemplateBuilder::build_route_data(&mut route_data, &router, "", "");
let router = Arc::new(Router::with_urls(vec![Route::with_router(
"/foo", sub_router,
)]));

ErrorPageTemplateBuilder::build_route_data(
&mut route_data,
&router,
&AbsolutePath::root(),
"",
);

assert_eq!(
route_data,
Expand All @@ -599,18 +628,61 @@ mod tests {
index: "0".to_string(),
path: "/foo".to_string(),
kind: "Root Router".to_string(),
name: String::new()
name: String::new(),
app: String::new()
},
RouteData {
index: "0.0".to_string(),
path: "/foo/bar".to_string(),
kind: "Router".to_string(),
name: String::new()
name: String::new(),
app: String::new()
}
]
);
}

#[test]
fn build_route_data_root_mount_no_double_slash() {
let mut route_data = Vec::new();
let sub_router = Router::with_urls(vec![Route::with_handler_and_name(
"/",
MockHandler,
"index",
)]);
let router = Arc::new(Router::with_urls(vec![Route::with_router("/", sub_router)]));

ErrorPageTemplateBuilder::build_route_data(
&mut route_data,
&router,
&AbsolutePath::root(),
"",
);

assert_eq!(route_data[0].path, "/");
assert_eq!(route_data[1].path, "/");
}

#[test]
fn build_route_data_root_mount_with_nested_static_route() {
let mut route_data = Vec::new();
let sub_router = Router::with_urls(vec![Route::with_handler_and_name(
"/nested",
MockHandler,
"nested",
)]);
let router = Arc::new(Router::with_urls(vec![Route::with_router("/", sub_router)]));

ErrorPageTemplateBuilder::build_route_data(
&mut route_data,
&router,
&AbsolutePath::root(),
"",
);

assert_eq!(route_data[1].path, "/nested");
}

#[test]
fn test_build_cot_failure_page() {
let response = build_cot_failure_page();
Expand Down
2 changes: 1 addition & 1 deletion cot/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
//! }
//!
//! fn register_apps(&self, apps: &mut AppBuilder, _context: &RegisterAppsContext) {
//! apps.register_with_views(SwaggerUi::new(), "/swagger");
//! apps.register_with_views(SwaggerUi::new(), "/swagger/");
//! apps.register_with_views(AddApp, "");
//! }
//! }
Expand Down
Loading
Loading