Skip to content

Commit def61fc

Browse files
committed
remove authority and scheme from http header
1 parent ae5d284 commit def61fc

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

crates/test-programs/src/bin/http_outbound_request_get.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
let uri = res.header("x-wasmtime-test-uri").unwrap();
2222
assert_eq!(
2323
std::str::from_utf8(uri).unwrap(),
24-
format!("http://{addr}/get?some=arg&goes=here")
24+
format!("/get?some=arg&goes=here")
2525
);
2626
assert_eq!(res.body, b"");
2727
}

crates/test-programs/src/bin/http_outbound_request_post.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ fn main() {
1818
assert_eq!(res.status, 200);
1919
let method = res.header("x-wasmtime-test-method").unwrap();
2020
assert_eq!(std::str::from_utf8(method).unwrap(), "POST");
21+
let uri = res.header("x-wasmtime-test-uri").unwrap();
22+
assert_eq!(std::str::from_utf8(uri).unwrap(), format!("/post"));
2123
assert_eq!(res.body, b"{\"foo\": \"bar\"}", "invalid body returned");
2224
}

crates/test-programs/src/bin/http_outbound_request_put.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ fn main() {
1212
assert_eq!(res.status, 200);
1313
let method = res.header("x-wasmtime-test-method").unwrap();
1414
assert_eq!(std::str::from_utf8(method).unwrap(), "PUT");
15+
let uri = res.header("x-wasmtime-test-uri").unwrap();
16+
assert_eq!(std::str::from_utf8(uri).unwrap(), format!("/put"));
1517
assert_eq!(res.body, b"");
1618
}

crates/wasi-http/src/types.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async fn handler(
144144
use_tls: bool,
145145
connect_timeout: Duration,
146146
first_byte_timeout: Duration,
147-
request: http::Request<HyperOutgoingBody>,
147+
mut request: http::Request<HyperOutgoingBody>,
148148
between_bytes_timeout: Duration,
149149
) -> Result<IncomingResponseInternal, types::ErrorCode> {
150150
let tcp_stream = TcpStream::connect(authority.clone())
@@ -244,6 +244,20 @@ async fn handler(
244244
(sender, worker)
245245
};
246246

247+
// at this point, the request contains the scheme and the authority, but
248+
// the http packet should only include those if addressing a proxy, so
249+
// remove them here, since SendRequest::send_request does not do it for us
250+
*request.uri_mut() = http::Uri::builder()
251+
.path_and_query(
252+
request
253+
.uri()
254+
.path_and_query()
255+
.map(|p| p.as_str())
256+
.unwrap_or("/"),
257+
)
258+
.build()
259+
.expect("comes from valid request");
260+
247261
let resp = timeout(first_byte_timeout, sender.send_request(request))
248262
.await
249263
.map_err(|_| types::ErrorCode::ConnectionReadTimeout)?

0 commit comments

Comments
 (0)