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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
let uri = res.header("x-wasmtime-test-uri").unwrap();
assert_eq!(
std::str::from_utf8(uri).unwrap(),
format!("http://{addr}/get?some=arg&goes=here")
format!("/get?some=arg&goes=here")
);
assert_eq!(res.body, b"");
}
2 changes: 2 additions & 0 deletions crates/test-programs/src/bin/http_outbound_request_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ fn main() {
assert_eq!(res.status, 200);
let method = res.header("x-wasmtime-test-method").unwrap();
assert_eq!(std::str::from_utf8(method).unwrap(), "POST");
let uri = res.header("x-wasmtime-test-uri").unwrap();
assert_eq!(std::str::from_utf8(uri).unwrap(), format!("/post"));
assert_eq!(res.body, b"{\"foo\": \"bar\"}", "invalid body returned");
}
2 changes: 2 additions & 0 deletions crates/test-programs/src/bin/http_outbound_request_put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ fn main() {
assert_eq!(res.status, 200);
let method = res.header("x-wasmtime-test-method").unwrap();
assert_eq!(std::str::from_utf8(method).unwrap(), "PUT");
let uri = res.header("x-wasmtime-test-uri").unwrap();
assert_eq!(std::str::from_utf8(uri).unwrap(), format!("/put"));
assert_eq!(res.body, b"");
}
16 changes: 15 additions & 1 deletion crates/wasi-http/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async fn handler(
use_tls: bool,
connect_timeout: Duration,
first_byte_timeout: Duration,
request: http::Request<HyperOutgoingBody>,
mut request: http::Request<HyperOutgoingBody>,
between_bytes_timeout: Duration,
) -> Result<IncomingResponseInternal, types::ErrorCode> {
let tcp_stream = TcpStream::connect(authority.clone())
Expand Down Expand Up @@ -244,6 +244,20 @@ async fn handler(
(sender, worker)
};

// at this point, the request contains the scheme and the authority, but
// the http packet should only include those if addressing a proxy, so
// remove them here, since SendRequest::send_request does not do it for us
*request.uri_mut() = http::Uri::builder()
.path_and_query(
request
.uri()
.path_and_query()
.map(|p| p.as_str())
.unwrap_or("/"),
)
.build()
.expect("comes from valid request");

let resp = timeout(first_byte_timeout, sender.send_request(request))
.await
.map_err(|_| types::ErrorCode::ConnectionReadTimeout)?
Expand Down