From dc495c58562c1cfe1732b62524154d713eb7632f Mon Sep 17 00:00:00 2001 From: Matthias Wright Date: Mon, 29 Apr 2024 21:38:23 +0800 Subject: [PATCH] feat(js-poc): separate query params from path --- services/js-poc/examples/js-poc-client.rs | 2 + services/js-poc/src/lib.rs | 56 ++++++++++++++++++----- services/js-poc/src/stream.rs | 4 ++ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/services/js-poc/examples/js-poc-client.rs b/services/js-poc/examples/js-poc-client.rs index c1b8006ef..458da848d 100644 --- a/services/js-poc/examples/js-poc-client.rs +++ b/services/js-poc/examples/js-poc-client.rs @@ -33,6 +33,8 @@ async fn main() -> anyhow::Result<()> { origin, uri, path: None, + query_params: None, + url_fragment: None, method: None, headers: None, param, diff --git a/services/js-poc/src/lib.rs b/services/js-poc/src/lib.rs index c735f42eb..39ba632fa 100644 --- a/services/js-poc/src/lib.rs +++ b/services/js-poc/src/lib.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use anyhow::{anyhow, bail, Context}; use arrayref::array_ref; use cid::Cid; @@ -110,6 +112,8 @@ async fn handle_request( origin, uri, path, + query_params: _, + url_fragment: _, method: _, headers: _, param, @@ -284,14 +288,16 @@ fn extract_request(url: &Url, body: &[u8], detail: &TransportDetail) -> Option = url + .query_pairs() + .map(|(key, val)| (key.to_string(), val.to_string())) + .collect(); + let query_params = if query_params.is_empty() { + None + } else { + Some(query_params) + }; let param = if body.is_empty() { url.query_pairs() @@ -315,6 +321,8 @@ fn extract_request(url: &Url, body: &[u8], detail: &TransportDetail) -> Option, + /// The query params from the url, if they exist + pub query_params: Option>, + /// The url fragment identifier, if it exists + pub url_fragment: Option, /// Http method pub method: Option, /// Headers from the http request