Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pull_request_template.md
Original file line number Diff line number Diff line change
@@ -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.}
18 changes: 18 additions & 0 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub struct IncomingHttpRequest {
source_socket_addr: Option<String>, // 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<String, String>, // will parse to http::HeaderMap
url_params: HashMap<String, String>,
query_params: HashMap<String, String>,
// BODY is stored in the lazy_load_blob, as bytes
}
Expand Down Expand Up @@ -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<String> {
let url = url::Url::parse(&self.url)?;
// skip the first path segment, which is the process ID.
Expand Down Expand Up @@ -260,6 +274,10 @@ impl IncomingHttpRequest {
header_map
}

pub fn url_params(&self) -> &HashMap<String, String> {
&self.url_params
}

pub fn query_params(&self) -> &HashMap<String, String> {
&self.query_params
}
Expand Down