From d3dfbca673b5ac3528a627346b68dbc2321d533b Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 20 Jun 2023 14:04:27 +0200 Subject: [PATCH] fix: manage auth bearer key and replace vars in body --- src/model/request.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/model/request.rs b/src/model/request.rs index febe318..65760d1 100644 --- a/src/model/request.rs +++ b/src/model/request.rs @@ -37,10 +37,24 @@ impl IntoRequest for v2_1_0::RequestClass { url_str = fill_from_env(url_str); - let url = reqwest::Url::from_str(&url_str).unwrap(); + let url = reqwest::Url::from_str(&url_str).unwrap_or_else(|e| { + eprintln!("error creating url ({}), falling back to localhost", e); + reqwest::Url::from_str("http://localhost/").unwrap() + }); let mut out = reqwest::Client::new().request(method, url); + // TODO handle more auth types than just bearer + if let Some(auth) = &self.auth { + if let Some(bearers) = &auth.bearer { + for bearer in bearers { + if let Some(value) = &bearer.value { + out = out.header("Authorization", format!("Bearer {}", value.as_str().unwrap_or(&value.to_string()))) + } + } + } + } + match &self.header { Some(v2_1_0::HeaderUnion::HeaderArray(x)) => { for h in x { @@ -52,9 +66,10 @@ impl IntoRequest for v2_1_0::RequestClass { _ => {}, } + match &self.body { Some(v2_1_0::Body { raw: Some(x), .. }) => { - out = out.body(x.clone()) // TODO try to avoid cloning? + out = out.body(fill_from_env(x.clone())) // TODO try to avoid cloning? }, _ => {}, }