Skip to content

Commit

Permalink
fix(js): conversion for uri port into string (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill authored Apr 25, 2024
1 parent b87d189 commit 06ec1c2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/cli/javascript/js_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ impl Display for Uri {
.collect::<Vec<String>>()
.join("&");

write!(f, "{}://{}{}{}", scheme, host, port, path)?;

if !query.is_empty() {
write!(f, "{}://{}:{}{}?{}", scheme, host, port, path, query)
} else {
write!(f, "{}://{}{}{}", scheme, host, port, path)
write!(f, "?{}", query)?;
}

Ok(())
}
}

Expand Down Expand Up @@ -118,6 +120,7 @@ impl TryFrom<&reqwest::Request> for JsRequest {

#[cfg(test)]
mod tests {
use hyper::HeaderMap;
use pretty_assertions::assert_eq;

use super::*;
Expand Down Expand Up @@ -154,6 +157,23 @@ mod tests {
assert_eq!(body_out, Some(body.to_string()));
}

#[test]
fn test_js_request_to_reqwest_request_with_port_and_query() {
let js_request = JsRequest {
uri: Uri::parse("http://localhost:3000/?test=abc").unwrap(),
method: "GET".to_string(),
headers: BTreeMap::default(),
body: None,
};
let reqwest_request: reqwest::Request = js_request.try_into().unwrap();
assert_eq!(reqwest_request.method(), reqwest::Method::GET);
assert_eq!(
reqwest_request.url().as_str(),
"http://localhost:3000/?test=abc"
);
assert_eq!(reqwest_request.headers(), &HeaderMap::default());
}

#[test]
fn test_reqwest_request_to_js_request() {
let mut reqwest_request =
Expand Down

1 comment on commit 06ec1c2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 7.63ms 3.56ms 96.61ms 72.86%
Req/Sec 3.32k 266.38 3.73k 87.00%

396517 requests in 30.02s, 1.99GB read

Requests/sec: 13210.46

Transfer/sec: 67.80MB

Please sign in to comment.