From 6074551219f2a86a0bb73b384cd7fec431e4146c Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Mon, 29 Apr 2024 01:45:17 +0330 Subject: [PATCH] respect http_proxy env var --- lib/wasix/src/http/reqwest.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/wasix/src/http/reqwest.rs b/lib/wasix/src/http/reqwest.rs index 036c1dda38f..cb84dc4267d 100644 --- a/lib/wasix/src/http/reqwest.rs +++ b/lib/wasix/src/http/reqwest.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{env, time::Duration}; use anyhow::Context; use futures::{future::BoxFuture, TryStreamExt}; @@ -44,10 +44,14 @@ impl ReqwestHttpClient { // TODO: use persistent client? let client = { let _guard = Handle::try_current().map_err(|_| self.handle.enter()); - reqwest::Client::builder() - .connect_timeout(self.connect_timeout) - .build() - .context("Could not create reqwest client")? + let mut builder = reqwest::Client::builder().connect_timeout(self.connect_timeout); + + let proxy = env::var("http_proxy").or_else(|_| env::var("HTTP_PROXY")); + if let Ok(scheme) = proxy { + builder = builder.proxy(reqwest::Proxy::all(scheme)?); + } + + builder.build().context("Could not create reqwest client")? }; let mut builder = client.request(method, request.url.as_str());