diff --git a/src/model/request.rs b/src/model/request.rs index 8c96e83..febe318 100644 --- a/src/model/request.rs +++ b/src/model/request.rs @@ -2,6 +2,16 @@ use std::str::FromStr; use postman_collection::{v1_0_0, v2_0_0, v2_1_0}; +fn fill_from_env(mut txt: String) -> String { + for (k, v) in std::env::vars() { + let key = format!("{{{{{}}}}}", k); + if txt.contains(&key) { + txt = txt.replace(&key, &v); + } + } + txt +} + pub trait IntoRequest { fn make_request(&self) -> reqwest::Request; } @@ -25,12 +35,7 @@ impl IntoRequest for v2_1_0::RequestClass { _ => "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); - } - } + url_str = fill_from_env(url_str); let url = reqwest::Url::from_str(&url_str).unwrap(); @@ -39,7 +44,9 @@ impl IntoRequest for v2_1_0::RequestClass { match &self.header { Some(v2_1_0::HeaderUnion::HeaderArray(x)) => { for h in x { - out = out.header(h.key.clone(), h.value.clone()); // TODO avoid cloning + let k = fill_from_env(h.key.clone()); + let v = fill_from_env(h.value.clone()); + out = out.header(k, v); // TODO avoid cloning } }, _ => {},