From e6c66ed9e79776827dd666db3dd031f572cd3128 Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Thu, 19 Nov 2020 21:45:41 -0500 Subject: [PATCH] Don't feature gate routing I really thought this was gonna be more complicated when I was planning it. Well, "planning" it. --- Cargo.toml | 1 - src/lib.rs | 1 - src/{routing/node.rs => routing.rs} | 16 +++++++++------- src/routing/mod.rs | 3 --- 4 files changed, 9 insertions(+), 12 deletions(-) rename src/{routing/node.rs => routing.rs} (89%) delete mode 100644 src/routing/mod.rs diff --git a/Cargo.toml b/Cargo.toml index b1e09a1..9ad991d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ documentation = "https://docs.rs/northstar" [features] default = ["serve_dir"] -routing = [] serve_dir = ["mime_guess", "tokio/fs"] [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 2279027..55df0b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,6 @@ use crate::util::opt_timeout; pub mod types; pub mod util; -#[cfg(feature="routing")] pub mod routing; pub use mime; diff --git a/src/routing/node.rs b/src/routing.rs similarity index 89% rename from src/routing/node.rs rename to src/routing.rs index b8bce21..3ba5aac 100644 --- a/src/routing/node.rs +++ b/src/routing.rs @@ -1,3 +1,7 @@ +//! Utilities for routing requests +//! +//! See [`RoutingNode`] for details on how routes are matched. + use uriparse::path::Path; use std::collections::HashMap; @@ -18,6 +22,9 @@ use crate::types::Request; /// "/trans/rights/r/human", then the longer route always matches first, so a request for /// "/trans/rights/r/human/rights" would be routed to "/trans/rights/r/human", and /// "/trans/rights/now" would route to "/trans/rights" +/// +/// Routing is only performed on normalized paths, so "/endpoint" and "/endpoint/" are +/// considered to be the same route. pub struct RoutingNode(Option, HashMap); impl RoutingNode { @@ -27,12 +34,7 @@ impl RoutingNode { /// represented as a sequence of path segments. For example, "/dir/image.png?text" /// should be represented as `&["dir", "image.png"]`. /// - /// Routing is performed only on normalized paths, so if a route exists for - /// "/endpoint", "/endpoint/" will also match, and vice versa. Routes also match all - /// requests for which they are the base of, meaning a request of "/api/endpoint" will - /// match a route of "/api" if no route exists specifically for "/api/endpoint". - /// - /// Longer routes automatically match before shorter routes. + /// See [`RoutingNode`] for details on how routes are matched. pub fn match_path(&self, path: I) -> Option<&Handler> where I: IntoIterator, @@ -60,7 +62,7 @@ impl RoutingNode { /// Attempt to identify a route for a given [`Request`] /// - /// See [`match_path()`](Self::match_path()) for how matching works + /// See [`RoutingNode`] for details on how routes are matched. pub fn match_request(&self, req: Request) -> Option<&Handler> { let mut path = req.path().to_owned(); path.normalize(false); diff --git a/src/routing/mod.rs b/src/routing/mod.rs deleted file mode 100644 index 5a41d23..0000000 --- a/src/routing/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Tools for adding routes to a [`Server`](crate::Server) -mod node; -pub use node::*;