Compare commits
4 commits
37f4d6b607
...
1798ce3f4e
Author | SHA1 | Date | |
---|---|---|---|
1798ce3f4e | |||
d504c650dd | |||
debccaf195 | |||
e44a69e93b |
5 changed files with 21 additions and 11 deletions
|
@ -34,3 +34,7 @@ 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}")
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ impl PrintableResult for ListResult {
|
|||
println!(" + {key}={}", crate::ext::stringify_toml(&value));
|
||||
}
|
||||
|
||||
for (name, endpoint) in collection.route {
|
||||
for (name, endpoint) in collection.route.unwrap_or_default() {
|
||||
let url = endpoint.url(collection.client.as_ref().and_then(|x| x.base.as_deref()))
|
||||
.split('?')
|
||||
.next()
|
||||
|
|
|
@ -150,8 +150,9 @@ async fn run_collection_endpoints(
|
|||
let client = std::sync::Arc::new(collection.client.unwrap_or_default());
|
||||
let env = std::sync::Arc::new(collection.env.unwrap_or_default());
|
||||
|
||||
for (name, mut endpoint) in collection.route {
|
||||
if pattern.find(&name).is_none() { continue };
|
||||
for (name, mut endpoint) in collection.route.unwrap_or_default() {
|
||||
let full_name = ext::full_name(&namespace, &name);
|
||||
if pattern.find(&full_name).is_none() { continue };
|
||||
|
||||
if debug { endpoint.extract = Some(ext::StringOr::T(model::ExtractorConfig::Debug)) };
|
||||
let _client = client.clone();
|
||||
|
@ -160,7 +161,7 @@ async fn run_collection_endpoints(
|
|||
|
||||
let task = async move {
|
||||
let before = chrono::Local::now();
|
||||
eprintln!(" : [{}] {_namespace}::{name} \tsending request...", before.format(fmt::TIMESTAMP_FMT));
|
||||
eprintln!(" : [{}] {full_name} \tsending request...", before.format(fmt::TIMESTAMP_FMT));
|
||||
|
||||
let res = if dry_run {
|
||||
Ok("".to_string())
|
||||
|
@ -211,7 +212,7 @@ fn load_collections(store: &mut IndexMap<String, PostWomanCollection>, mut path:
|
|||
},
|
||||
};
|
||||
|
||||
let name = path.to_string_lossy().to_string();
|
||||
let name = path.to_string_lossy().replace(".toml", "");
|
||||
let mut to_include = Vec::new();
|
||||
|
||||
if let Some(ref includes) = collection.include {
|
||||
|
|
|
@ -223,11 +223,16 @@ fn replace_recursive(element: toml::Value, from: &str, to: &str) -> toml::Value
|
|||
|
||||
async fn format_body(res: reqwest::Response) -> Result<String, PostWomanError> {
|
||||
match res.headers().get("Content-Type") {
|
||||
None => Ok(res.text().await? + "\n"),
|
||||
Some(v) => match v.to_str()? {
|
||||
"application/json" => Ok(serde_json::to_string_pretty(&res.json::<serde_json::Value>().await?)? + "\n"),
|
||||
"text/plain" | "text/html" => Ok(res.text().await? + "\n"),
|
||||
_ => Ok(format!("base64({})\n", BASE64_STANDARD.encode(res.bytes().await?))),
|
||||
None => Ok(res.text().await?),
|
||||
Some(v) => {
|
||||
let content_type = v.to_str()?;
|
||||
if content_type.starts_with("application/json") {
|
||||
Ok(serde_json::to_string_pretty(&res.json::<serde_json::Value>().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?)))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ pub struct PostWomanCollection {
|
|||
pub env: Option<toml::Table>,
|
||||
pub include: Option<Vec<String>>,
|
||||
// it's weird to name it singular but makes more sense in config
|
||||
pub route: indexmap::IndexMap<String, EndpointConfig>,
|
||||
pub route: Option<indexmap::IndexMap<String, EndpointConfig>>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue