|
1 | 1 | use masking::{Maskable, Secret}; |
2 | | -#[cfg(feature = "logs")] |
3 | | -use router_env::logger; |
4 | 2 | use serde::{Deserialize, Serialize}; |
5 | 3 |
|
6 | | -use crate::errors; |
7 | | - |
8 | 4 | pub type Headers = std::collections::HashSet<(String, Maskable<String>)>; |
9 | 5 |
|
10 | 6 | #[derive( |
@@ -64,6 +60,18 @@ pub enum RequestContent { |
64 | 60 | RawBytes(Vec<u8>), |
65 | 61 | } |
66 | 62 |
|
| 63 | +impl RequestContent { |
| 64 | + pub fn get_inner_value(&self) -> Secret<String> { |
| 65 | + match self { |
| 66 | + Self::Json(i) => serde_json::to_string(&i).unwrap_or_default().into(), |
| 67 | + Self::FormUrlEncoded(i) => serde_urlencoded::to_string(i).unwrap_or_default().into(), |
| 68 | + Self::Xml(i) => quick_xml::se::to_string(&i).unwrap_or_default().into(), |
| 69 | + Self::FormData(_) => String::new().into(), |
| 70 | + Self::RawBytes(_) => String::new().into(), |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | + |
67 | 75 | impl Request { |
68 | 76 | pub fn new(method: Method, url: &str) -> Self { |
69 | 77 | Self { |
@@ -176,33 +184,3 @@ impl Default for RequestBuilder { |
176 | 184 | Self::new() |
177 | 185 | } |
178 | 186 | } |
179 | | - |
180 | | -#[derive(Clone, Debug)] |
181 | | -pub struct RequestBody(Secret<String>); |
182 | | - |
183 | | -impl RequestBody { |
184 | | - pub fn log_and_get_request_body<T, F>( |
185 | | - body: T, |
186 | | - encoder: F, |
187 | | - ) -> errors::CustomResult<Self, errors::ParsingError> |
188 | | - where |
189 | | - F: FnOnce(T) -> errors::CustomResult<String, errors::ParsingError>, |
190 | | - T: std::fmt::Debug, |
191 | | - { |
192 | | - #[cfg(feature = "logs")] |
193 | | - logger::info!(connector_request_body=?body); |
194 | | - Ok(Self(Secret::new(encoder(body)?))) |
195 | | - } |
196 | | - |
197 | | - pub fn get_inner_value(request_body: RequestContent) -> Secret<String> { |
198 | | - match request_body { |
199 | | - RequestContent::Json(i) => serde_json::to_string(&i).unwrap_or_default().into(), |
200 | | - RequestContent::FormUrlEncoded(i) => { |
201 | | - serde_urlencoded::to_string(&i).unwrap_or_default().into() |
202 | | - } |
203 | | - RequestContent::Xml(i) => quick_xml::se::to_string(&i).unwrap_or_default().into(), |
204 | | - RequestContent::FormData(_) => String::new().into(), |
205 | | - RequestContent::RawBytes(_) => String::new().into(), |
206 | | - } |
207 | | - } |
208 | | -} |
0 commit comments