Skip to content

Commit

Permalink
Fix scheme for URIs, add coverage to detect regressions in the future. (
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns authored May 16, 2023
1 parent 3f03130 commit f271adf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async fn test(
Response::builder()
.status(http::StatusCode::OK)
.header("x-wasmtime-test-method", method)
.header("x-wasmtime-test-uri", req.uri().to_string())
.body(req.into_body().boxed())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ fn main() -> Result<()> {
assert_eq!(r1.status, 200);
let method = r1.header("x-wasmtime-test-method").unwrap();
assert_eq!(method, "GET");
let uri = r1.header("x-wasmtime-test-uri").unwrap();
assert_eq!(uri, "http://localhost:3000/get?some=arg?goes=here");
assert_eq!(r1.body, b"");

let r2 = request(
Expand Down
13 changes: 5 additions & 8 deletions crates/wasi-http/src/http_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,11 @@ impl WasiHttp {
crate::types::Method::Other(s) => bail!("unknown method {}", s),
};

let scheme = format!(
"{}://",
match request.scheme.as_ref().unwrap_or(&Scheme::Https) {
Scheme::Http => "http://",
Scheme::Https => "https://",
Scheme::Other(s) => bail!("unsupported scheme {}", s),
}
);
let scheme = match request.scheme.as_ref().unwrap_or(&Scheme::Https) {
Scheme::Http => "http://",
Scheme::Https => "https://",
Scheme::Other(s) => bail!("unsupported scheme {}", s),
};

// Largely adapted from https://hyper.rs/guides/1/client/basic/
let authority = match request.authority.find(":") {
Expand Down

0 comments on commit f271adf

Please sign in to comment.