Skip to content

Commit b03a66b

Browse files
committed
Teach outbound-http to use connection pool
`reqwest::Client` manages an internal connection pool. For executions that make multiple requests to the same host we can take advantage of that pool. Signed-off-by: Lann Martin <lann.martin@fermyon.com>
1 parent dfb3a90 commit b03a66b

File tree

1 file changed

+5
-5
lines changed
  • crates/outbound-http/src

1 file changed

+5
-5
lines changed

crates/outbound-http/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ use wasi_outbound_http::*;
1818
pub struct OutboundHttp {
1919
/// List of hosts guest modules are allowed to make requests to.
2020
pub allowed_hosts: AllowedHttpHosts,
21+
client: Option<Client>,
2122
}
2223

2324
impl OutboundHttp {
24-
pub fn new(allowed_hosts: AllowedHttpHosts) -> Self {
25-
Self { allowed_hosts }
26-
}
27-
2825
/// Check if guest module is allowed to send request to URL, based on the list of
2926
/// allowed hosts defined by the runtime. If the list of allowed hosts contains
3027
/// `insecure:allow-all`, then all hosts are allowed.
@@ -52,7 +49,10 @@ impl wasi_outbound_http::WasiOutboundHttp for OutboundHttp {
5249
tracing::log::warn!("HTTP params field is deprecated");
5350
}
5451

55-
let client = Client::builder().build().unwrap();
52+
// Allow reuse of Client's internal connection pool for multiple requests
53+
// in a single component execution
54+
let client = self.client.get_or_insert_with(Default::default);
55+
5656
let resp = client
5757
.request(method, url)
5858
.headers(headers)

0 commit comments

Comments
 (0)