fix: match content-type with .starts_with()
This commit is contained in:
parent
e44a69e93b
commit
debccaf195
1 changed files with 10 additions and 5 deletions
|
@ -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> {
|
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? + "\n"),
|
None => Ok(res.text().await?),
|
||||||
Some(v) => match v.to_str()? {
|
Some(v) => {
|
||||||
"application/json" => Ok(serde_json::to_string_pretty(&res.json::<serde_json::Value>().await?)? + "\n"),
|
let content_type = v.to_str()?;
|
||||||
"text/plain" | "text/html" => Ok(res.text().await? + "\n"),
|
if content_type.starts_with("application/json") {
|
||||||
_ => Ok(format!("base64({})\n", BASE64_STANDARD.encode(res.bytes().await?))),
|
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?)))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue