From 748b149b19f0160e95c8d4a74ede49c4e663cafa Mon Sep 17 00:00:00 2001 From: "nick.kino" <79381743+hosted-fornet@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:59:48 -0800 Subject: [PATCH 1/4] add pull_request_template.md --- pull_request_template.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 pull_request_template.md diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..fff18e8 --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,15 @@ +## Problem + +{A brief description of the problem, along with necessary context.} + +## Solution + +{A brief description of how you solved the problem.} + +## Docs Update + +[Corresponding docs PR](https://github.com/kinode-dao/kinode-book/pull/my-pr-number) + +## Notes + +{Any other information useful for reviewers.} From e14f2128a730f126ecc9a7fb1d6fd45acd20f9ae Mon Sep 17 00:00:00 2001 From: Will Galebach Date: Thu, 15 Feb 2024 16:07:02 +0000 Subject: [PATCH 2/4] Updated to new IncomingHttpRequest format --- src/http.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/http.rs b/src/http.rs index d557d06..5b4cc69 100644 --- a/src/http.rs +++ b/src/http.rs @@ -44,7 +44,9 @@ pub struct IncomingHttpRequest { source_socket_addr: Option, // will parse to SocketAddr method: String, // will parse to http::Method url: String, // will parse to url::Url + bound_path: String, // the matching path that was bound headers: HashMap, // will parse to http::HeaderMap + url_params: HashMap, query_params: HashMap, // BODY is stored in the lazy_load_blob, as bytes } @@ -233,6 +235,13 @@ impl IncomingHttpRequest { } } + pub fn bound_path(&self, strip_prefix: Option<&str>) -> String { + self + .bound_path + .replace(strip_prefix.unwrap_or(""), "") + .replace("//", "/") + } + pub fn path(&self) -> anyhow::Result { let url = url::Url::parse(&self.url)?; // skip the first path segment, which is the process ID. @@ -260,6 +269,10 @@ impl IncomingHttpRequest { header_map } + pub fn url_params(&self) -> &HashMap { + &self.url_params + } + pub fn query_params(&self) -> &HashMap { &self.query_params } From 5e5ef1cbd8289c46b541aeb95bb47ed99b34761b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:07:27 +0000 Subject: [PATCH 3/4] Format Rust code using rustfmt --- src/http.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/http.rs b/src/http.rs index 5b4cc69..2ac90dd 100644 --- a/src/http.rs +++ b/src/http.rs @@ -236,8 +236,7 @@ impl IncomingHttpRequest { } pub fn bound_path(&self, strip_prefix: Option<&str>) -> String { - self - .bound_path + self.bound_path .replace(strip_prefix.unwrap_or(""), "") .replace("//", "/") } From c0900d7cbabbb5782ef2e3ca67ce461198446d5f Mon Sep 17 00:00:00 2001 From: Will Galebach Date: Thu, 15 Feb 2024 18:36:22 +0000 Subject: [PATCH 4/4] Add docstring and update bound_path() --- src/http.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/http.rs b/src/http.rs index 2ac90dd..885cb52 100644 --- a/src/http.rs +++ b/src/http.rs @@ -235,10 +235,16 @@ impl IncomingHttpRequest { } } - pub fn bound_path(&self, strip_prefix: Option<&str>) -> String { - self.bound_path - .replace(strip_prefix.unwrap_or(""), "") - .replace("//", "/") + /// Returns the path that was originally bound, with an optional prefix stripped. + /// The prefix would normally be the process ID as a &str, but it could be anything. + pub fn bound_path(&self, process_id_to_strip: Option<&str>) -> &str { + match process_id_to_strip { + Some(process_id) => self + .bound_path + .strip_prefix(&format!("/{}", process_id)) + .unwrap_or(&self.bound_path), + None => &self.bound_path, + } } pub fn path(&self) -> anyhow::Result {