Don't feature gate routing

I really thought this was gonna be more complicated when I was planning it.  Well,
"planning" it.
This commit is contained in:
Emi Tatsuo 2020-11-19 21:45:41 -05:00
parent 26e0fd2702
commit e6c66ed9e7
Signed by: Emi
GPG Key ID: 68FAB2E2E6DFC98B
4 changed files with 9 additions and 12 deletions

View File

@ -10,7 +10,6 @@ documentation = "https://docs.rs/northstar"
[features]
default = ["serve_dir"]
routing = []
serve_dir = ["mime_guess", "tokio/fs"]
[dependencies]

View File

@ -25,7 +25,6 @@ use crate::util::opt_timeout;
pub mod types;
pub mod util;
#[cfg(feature="routing")]
pub mod routing;
pub use mime;

View File

@ -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<Handler>, HashMap<String, Self>);
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<I,S>(&self, path: I) -> Option<&Handler>
where
I: IntoIterator<Item=S>,
@ -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);

View File

@ -1,3 +0,0 @@
//! Tools for adding routes to a [`Server`](crate::Server)
mod node;
pub use node::*;