Fix Uri extractor not being the full URI if using nest (#156)

This commit is contained in:
David Pedersen
2021-08-07 22:07:50 +02:00
committed by GitHub
parent a6b3e09827
commit c570fb2d52
4 changed files with 49 additions and 2 deletions
+10
View File
@@ -907,6 +907,11 @@ where
}
fn call(&mut self, mut req: Request<B>) -> Self::Future {
if req.extensions().get::<OriginalUri>().is_none() {
let original_uri = OriginalUri(req.uri().clone());
req.extensions_mut().insert(original_uri);
}
if let Some((prefix, captures)) = self.pattern.prefix_match(req.uri().path()) {
let without_prefix = strip_prefix(req.uri(), prefix);
*req.uri_mut() = without_prefix;
@@ -921,6 +926,11 @@ where
}
}
/// `Nested` changes the incoming requests URI. This will be saved as an
/// extension so extractors can still access the original URI.
#[derive(Clone)]
pub(crate) struct OriginalUri(pub(crate) Uri);
fn strip_prefix(uri: &Uri, prefix: &str) -> Uri {
let path_and_query = if let Some(path_and_query) = uri.path_and_query() {
let new_path = if let Some(path) = path_and_query.path().strip_prefix(prefix) {