Skip to content

Commit

Permalink
fix: empty body shouldn't default to {}
Browse files Browse the repository at this point in the history
  • Loading branch information
alemidev committed Oct 19, 2024
1 parent a5cef7f commit 7887e0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ async fn run_postwoman(args: PostWomanArgs, collection: PostWomanCollection) ->
println!(" |: {header}");
}
}
if let Ok(body) = endpoint.body() {
println!(" |> {body}");
if let Some(ref _x) = endpoint.body {
if let Ok(body) = endpoint.body() {
println!(" |> {body}");
} else {
println!(" |> [!] invalid body");
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/model/endpoint.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)?),
}
}

Expand Down

0 comments on commit 7887e0d

Please # to comment.