From 3da462813fc5900e919637e4dd7bc974752d2dea Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Mon, 29 Jul 2024 16:59:37 +0800 Subject: [PATCH] wip --- crates/core/src/routing/mod.rs | 2 +- crates/oapi/src/swagger_ui/mod.rs | 2 +- crates/proxy/src/lib.rs | 2 +- crates/serve-static/src/dir.rs | 2 +- crates/serve-static/src/embed.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/core/src/routing/mod.rs b/crates/core/src/routing/mod.rs index 8cd32dbee..cbafb092e 100644 --- a/crates/core/src/routing/mod.rs +++ b/crates/core/src/routing/mod.rs @@ -412,7 +412,7 @@ impl PathParams { self.greedy } /// Get the last param starts with '*', for example: <**rest>, <*?rest>. - pub fn star(&self) -> Option<&str> { + pub fn tail(&self) -> Option<&str> { if self.greedy { self.inner.last().map(|(_, v)| &**v) } else { diff --git a/crates/oapi/src/swagger_ui/mod.rs b/crates/oapi/src/swagger_ui/mod.rs index 6bd0b4e09..fcb9d278b 100644 --- a/crates/oapi/src/swagger_ui/mod.rs +++ b/crates/oapi/src/swagger_ui/mod.rs @@ -238,7 +238,7 @@ impl Handler for SwaggerUi { redirect_to_dir_url(req.uri(), res); return; } - let Some(path) = req.params().star() else { + let Some(path) = req.params().tail() else { res.render(StatusError::not_found().detail("The router params is incorrect. The params should ending with a wildcard.")); return; }; diff --git a/crates/proxy/src/lib.rs b/crates/proxy/src/lib.rs index 2d3b04b5a..9fb25b868 100644 --- a/crates/proxy/src/lib.rs +++ b/crates/proxy/src/lib.rs @@ -137,7 +137,7 @@ pub type UrlPartGetter = Box Option + Send + /// This getter will get the last param as the rest url path from request. /// In most case you should use wildcard param, like `<**rest>`, `<*+rest>`. pub fn default_url_path_getter(req: &Request, _depot: &Depot) -> Option { - req.params().star().map(encode_url_path) + req.params().tail().map(encode_url_path) } /// Default url query getter. This getter just return the query string from request uri. pub fn default_url_query_getter(req: &Request, _depot: &Depot) -> Option { diff --git a/crates/serve-static/src/dir.rs b/crates/serve-static/src/dir.rs index 1c4fac1e7..29cbde2be 100644 --- a/crates/serve-static/src/dir.rs +++ b/crates/serve-static/src/dir.rs @@ -288,7 +288,7 @@ impl DirInfo { impl Handler for StaticDir { async fn handle(&self, req: &mut Request, _depot: &mut Depot, res: &mut Response, _ctrl: &mut FlowCtrl) { let req_path = req.uri().path(); - let rel_path = if let Some(rest) = req.params().star() { + let rel_path = if let Some(rest) = req.params().tail() { rest } else { &*decode_url_path_safely(req_path) diff --git a/crates/serve-static/src/embed.rs b/crates/serve-static/src/embed.rs index 836dd6868..c7895d679 100644 --- a/crates/serve-static/src/embed.rs +++ b/crates/serve-static/src/embed.rs @@ -114,7 +114,7 @@ where T: RustEmbed + Send + Sync + 'static, { async fn handle(&self, req: &mut Request, _depot: &mut Depot, res: &mut Response, _ctrl: &mut FlowCtrl) { - let req_path = if let Some(rest) = req.params().star() { + let req_path = if let Some(rest) = req.params().tail() { rest } else { &*decode_url_path_safely(req.uri().path())