Skip to content

Commit

Permalink
Print request/response bodies as formatted JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
mcastorina committed Jul 25, 2020
1 parent 51df22d commit 95a287f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ fn get_json_values(root: &Value, query: &str) -> Result<Vec<Value>> {
Ok(vec![result.take()])
}

fn display_body(text: &str, no_pager: bool) {
pub fn display_body(text: &str, no_pager: bool) {
let v: serde_json::Result<serde_json::Value> = serde_json::from_str(text);
let text = match v {
Ok(v) => format!("{}\n", serde_json::to_string_pretty(&v).unwrap()),
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ pub fn response(b: &Bastion, matches: &ArgMatches) -> Result<()> {
if let Some(body) = rr.request_body() {
println!("{}", " Request Body".bold());
println!(" ==============");
println!("{}\n", std::str::from_utf8(body).unwrap());
super::run::display_body(std::str::from_utf8(body).unwrap(), true);
println!();
}
}

Expand All @@ -100,7 +101,8 @@ pub fn response(b: &Bastion, matches: &ArgMatches) -> Result<()> {
if let Some(body) = rr.response_body() {
println!("{}", " Response Body".bold());
println!(" ===============");
println!("{}\n", std::str::from_utf8(body).unwrap());
super::run::display_body(std::str::from_utf8(body).unwrap(), true);
println!();
}

let extractions = rr.extractions();
Expand Down

0 comments on commit 95a287f

Please sign in to comment.