Skip to content

Commit

Permalink
feat(js-poc): include http method in params passed to js func
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed Apr 29, 2024
1 parent aae531b commit c86feea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/sdk/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct ConnectionHeader {
pub transport_detail: TransportDetail,
}

#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, PartialOrd)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, PartialOrd, Eq)]
pub enum HttpMethod {
Get,
Post,
Expand Down
1 change: 1 addition & 0 deletions services/js-poc/examples/js-poc-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async fn main() -> anyhow::Result<()> {
origin,
uri,
path: None,
method: None,
headers: None,
param,
})
Expand Down
15 changes: 12 additions & 3 deletions services/js-poc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async fn handle_request(
origin,
uri,
path,
method: _,
headers: _,
param,
} = request;
Expand Down Expand Up @@ -304,16 +305,17 @@ fn extract_request(url: &Url, body: &[u8], detail: &TransportDetail) -> Option<R
Some(serde_json::from_slice::<serde_json::Value>(body).ok()?)
};

let headers = if let TransportDetail::HttpRequest { header, .. } = &detail {
Some(header.clone())
let (headers, method) = if let TransportDetail::HttpRequest { header, method, .. } = &detail {
(Some(header.clone()), Some(*method))
} else {
None
(None, None)
};

Some(Request {
origin,
uri: seg2.to_string(),
path: Some(path),
method,
headers,
param,
})
Expand Down Expand Up @@ -341,6 +343,7 @@ mod tests {
origin: Origin::Blake3,
uri: "content-hash".to_string(),
path: Some("/".to_string()),
method: None,
headers: None,
param: None,
})
Expand All @@ -356,6 +359,7 @@ mod tests {
origin: Origin::Blake3,
uri: "content-hash".to_string(),
path: Some("/a".to_string()),
method: None,
headers: None,
param: None,
})
Expand All @@ -371,6 +375,7 @@ mod tests {
origin: Origin::Blake3,
uri: "content-hash".to_string(),
path: Some("/a/b".to_string()),
method: None,
headers: None,
param: None,
})
Expand All @@ -386,6 +391,7 @@ mod tests {
origin: Origin::Blake3,
uri: "content-hash".to_string(),
path: Some("/a/b?a=4".to_string()),
method: None,
headers: None,
param: None,
})
Expand All @@ -401,6 +407,7 @@ mod tests {
origin: Origin::Blake3,
uri: "content-hash".to_string(),
path: Some("/a/b?a=4#hello".to_string()),
method: None,
headers: None,
param: None,
})
Expand All @@ -419,6 +426,7 @@ mod tests {
origin: Origin::Blake3,
uri: "content-hash".to_string(),
path: Some("/a/b?a=4&param=%7B%22a%22%3A%204%7D#hello".to_string()),
method: None,
headers: None,
param: Some(json!({"a": 4})),
})
Expand All @@ -437,6 +445,7 @@ mod tests {
origin: Origin::Blake3,
uri: "content-hash".to_string(),
path: Some("/a/b?a=4&param=%7B%22a%22%3A%204%7D#hello".to_string()),
method: None,
headers: None,
param: Some(json!({"hello": 5})),
})
Expand Down
3 changes: 3 additions & 0 deletions services/js-poc/src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use fn_sdk::api::Origin as ApiOrigin;
use fn_sdk::header::HttpMethod;
use serde::{Deserialize, Serialize};

/// Request to execute some javascript from an origin
Expand All @@ -14,6 +15,8 @@ pub struct Request {
pub uri: String,
/// Optional path to provide as the window location
pub path: Option<String>,
/// Http method
pub method: Option<HttpMethod>,
/// Headers from the http request
pub headers: Option<HashMap<String, String>>,
/// Parameter to pass to the script's main function
Expand Down

0 comments on commit c86feea

Please sign in to comment.