feat: also fill header vars from env
This commit is contained in:
parent
2dd2e6e0ec
commit
527af4e54f
1 changed files with 14 additions and 7 deletions
|
@ -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
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
|
|
Loading…
Reference in a new issue