From 7887e0dfdb485f9ef3ee2ec0dd0615e0ea44e0a3 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 20 Oct 2024 01:55:14 +0200 Subject: [PATCH] fix: empty body shouldn't default to {} --- src/main.rs | 8 ++++++-- src/model/endpoint.rs | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 73cd45d..664b185 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); + } } } } diff --git a/src/model/endpoint.rs b/src/model/endpoint.rs index 66b0d93..8428e11 100644 --- a/src/model/endpoint.rs +++ b/src/model/endpoint.rs @@ -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 { - 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)?), } }