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.} diff --git a/src/http.rs b/src/http.rs index d557d06..885cb52 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,18 @@ impl IncomingHttpRequest { } } + /// 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 { let url = url::Url::parse(&self.url)?; // skip the first path segment, which is the process ID. @@ -260,6 +274,10 @@ impl IncomingHttpRequest { header_map } + pub fn url_params(&self) -> &HashMap { + &self.url_params + } + pub fn query_params(&self) -> &HashMap { &self.query_params }