From 3040556976bc3f1ea35934b4331452d8f246ad23 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 15 Jun 2023 16:23:48 +0200 Subject: [PATCH] feat: replace vars in urls from OS environment --- src/model/request.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/model/request.rs b/src/model/request.rs index 40bc8ba..8c96e83 100644 --- a/src/model/request.rs +++ b/src/model/request.rs @@ -18,13 +18,20 @@ impl IntoRequest for v2_1_0::RequestClass { &self.method.as_ref().unwrap_or(&"GET".into()).as_bytes() // TODO lol? ).unwrap_or(reqwest::Method::GET); // TODO throw an error rather than replacing it silently - let url_str = match &self.url { - Some(v2_1_0::Url::String(x)) => x, - Some(v2_1_0::Url::UrlClass(v2_1_0::UrlClass { raw: Some(x), .. })) => x, + let mut url_str = match &self.url { + Some(v2_1_0::Url::String(x)) => x.clone(), + Some(v2_1_0::Url::UrlClass(v2_1_0::UrlClass { raw: Some(x), .. })) => x.clone(), // TODO compose URL from UrlClass rather than only accepting those with raw set - _ => "http://localhost", + _ => "http://localhost".into(), }; + for (k, v) in std::env::vars() { + let key = format!("{{{{{}}}}}", k); + if url_str.contains(&key) { + url_str = url_str.replace(&key, &v); + } + } + let url = reqwest::Url::from_str(&url_str).unwrap(); let mut out = reqwest::Client::new().request(method, url);