Skip to content

Commit

Permalink
Merge pull request #796 from lann/outbound-http-pool
Browse files Browse the repository at this point in the history
Teach outbound-http to use connection pool
  • Loading branch information
lann authored Sep 30, 2022
2 parents dfb3a90 + b03a66b commit 13f7916
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/outbound-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ use wasi_outbound_http::*;
pub struct OutboundHttp {
/// List of hosts guest modules are allowed to make requests to.
pub allowed_hosts: AllowedHttpHosts,
client: Option<Client>,
}

impl OutboundHttp {
pub fn new(allowed_hosts: AllowedHttpHosts) -> Self {
Self { allowed_hosts }
}

/// Check if guest module is allowed to send request to URL, based on the list of
/// allowed hosts defined by the runtime. If the list of allowed hosts contains
/// `insecure:allow-all`, then all hosts are allowed.
Expand Down Expand Up @@ -52,7 +49,10 @@ impl wasi_outbound_http::WasiOutboundHttp for OutboundHttp {
tracing::log::warn!("HTTP params field is deprecated");
}

let client = Client::builder().build().unwrap();
// Allow reuse of Client's internal connection pool for multiple requests
// in a single component execution
let client = self.client.get_or_insert_with(Default::default);

let resp = client
.request(method, url)
.headers(headers)
Expand Down

0 comments on commit 13f7916

Please sign in to comment.