Compare commits

..

No commits in common. "1798ce3f4ec7db2bf745a240f76cb0fe64c5e988" and "37f4d6b607e7d671a9d9bbee93b2ba9275d7a9ee" have entirely different histories.

5 changed files with 11 additions and 21 deletions

View file

@ -34,7 +34,3 @@ pub fn stringify_json(v: &serde_json::Value) -> String {
} }
} }
// keep it as separate fn so we can change it everywhere easily
pub fn full_name(namespace: &str, name: &str) -> String {
format!("{namespace}:{name}")
}

View file

@ -63,7 +63,7 @@ impl PrintableResult for ListResult {
println!(" + {key}={}", crate::ext::stringify_toml(&value)); println!(" + {key}={}", crate::ext::stringify_toml(&value));
} }
for (name, endpoint) in collection.route.unwrap_or_default() { for (name, endpoint) in collection.route {
let url = endpoint.url(collection.client.as_ref().and_then(|x| x.base.as_deref())) let url = endpoint.url(collection.client.as_ref().and_then(|x| x.base.as_deref()))
.split('?') .split('?')
.next() .next()

View file

@ -150,9 +150,8 @@ async fn run_collection_endpoints(
let client = std::sync::Arc::new(collection.client.unwrap_or_default()); let client = std::sync::Arc::new(collection.client.unwrap_or_default());
let env = std::sync::Arc::new(collection.env.unwrap_or_default()); let env = std::sync::Arc::new(collection.env.unwrap_or_default());
for (name, mut endpoint) in collection.route.unwrap_or_default() { for (name, mut endpoint) in collection.route {
let full_name = ext::full_name(&namespace, &name); if pattern.find(&name).is_none() { continue };
if pattern.find(&full_name).is_none() { continue };
if debug { endpoint.extract = Some(ext::StringOr::T(model::ExtractorConfig::Debug)) }; if debug { endpoint.extract = Some(ext::StringOr::T(model::ExtractorConfig::Debug)) };
let _client = client.clone(); let _client = client.clone();
@ -161,7 +160,7 @@ async fn run_collection_endpoints(
let task = async move { let task = async move {
let before = chrono::Local::now(); let before = chrono::Local::now();
eprintln!(" : [{}] {full_name} \tsending request...", before.format(fmt::TIMESTAMP_FMT)); eprintln!(" : [{}] {_namespace}::{name} \tsending request...", before.format(fmt::TIMESTAMP_FMT));
let res = if dry_run { let res = if dry_run {
Ok("".to_string()) Ok("".to_string())
@ -212,7 +211,7 @@ fn load_collections(store: &mut IndexMap<String, PostWomanCollection>, mut path:
}, },
}; };
let name = path.to_string_lossy().replace(".toml", ""); let name = path.to_string_lossy().to_string();
let mut to_include = Vec::new(); let mut to_include = Vec::new();
if let Some(ref includes) = collection.include { if let Some(ref includes) = collection.include {

View file

@ -223,16 +223,11 @@ fn replace_recursive(element: toml::Value, from: &str, to: &str) -> toml::Value
async fn format_body(res: reqwest::Response) -> Result<String, PostWomanError> { async fn format_body(res: reqwest::Response) -> Result<String, PostWomanError> {
match res.headers().get("Content-Type") { match res.headers().get("Content-Type") {
None => Ok(res.text().await?), None => Ok(res.text().await? + "\n"),
Some(v) => { Some(v) => match v.to_str()? {
let content_type = v.to_str()?; "application/json" => Ok(serde_json::to_string_pretty(&res.json::<serde_json::Value>().await?)? + "\n"),
if content_type.starts_with("application/json") { "text/plain" | "text/html" => Ok(res.text().await? + "\n"),
Ok(serde_json::to_string_pretty(&res.json::<serde_json::Value>().await?)?) _ => Ok(format!("base64({})\n", BASE64_STANDARD.encode(res.bytes().await?))),
} else if content_type.starts_with("text/plain") || content_type.starts_with("text/html") {
Ok(res.text().await?)
} else {
Ok(format!("base64({})\n", BASE64_STANDARD.encode(res.bytes().await?)))
}
}, },
} }
} }

View file

@ -12,5 +12,5 @@ pub struct PostWomanCollection {
pub env: Option<toml::Table>, pub env: Option<toml::Table>,
pub include: Option<Vec<String>>, pub include: Option<Vec<String>>,
// it's weird to name it singular but makes more sense in config // it's weird to name it singular but makes more sense in config
pub route: Option<indexmap::IndexMap<String, EndpointConfig>>, pub route: indexmap::IndexMap<String, EndpointConfig>,
} }