fix: empty body shouldn't default to {}

This commit is contained in:
əlemi 2024-10-20 01:55:14 +02:00
parent a5cef7f269
commit 7887e0dfdb
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 10 additions and 6 deletions

View file

@ -104,8 +104,12 @@ async fn run_postwoman(args: PostWomanArgs, collection: PostWomanCollection) ->
println!(" |: {header}");
}
}
if let Some(ref _x) = endpoint.body {
if let Ok(body) = endpoint.body() {
println!(" |> {body}");
} else {
println!(" |> [!] invalid body");
}
}
}
}

View file

@ -1,7 +1,6 @@
use std::{collections::HashMap, str::FromStr};
use base64::{prelude::BASE64_STANDARD, Engine};
use http::header::{InvalidHeaderName, InvalidHeaderValue};
use http::method::InvalidMethod;
use http::{HeaderMap, HeaderName, HeaderValue};
use jaq_interpret::FilterT;
@ -33,9 +32,10 @@ pub struct EndpointConfig {
impl EndpointConfig {
pub fn body(&mut self) -> Result<String, serde_json::Error> {
match self.body.take().unwrap_or_default() {
StringOr::Str(x) => Ok(x.clone()),
StringOr::T(json) => Ok(serde_json::to_string(&json)?),
match self.body.take() {
None => Ok("".to_string()),
Some(StringOr::Str(x)) => Ok(x.clone()),
Some(StringOr::T(json)) => Ok(serde_json::to_string(&json)?),
}
}