httpyac / httpyac.github.io

Documentation and Examples for httpyac
https://httpyac.github.io
MIT License
105 stars 10 forks source link

repeat responses are lost with --json formatting option #69

Closed dinurp closed 1 year ago

dinurp commented 1 year ago

I am trying to find the response times of repeated request. I saw that the timings in the response would be useful for this. httpyac send post.http -n post --repeat 2 --repeat-mode serial > .\post-log.json after cleaning up the file,

jq '.responses[].timings' .\post-log.json
{
  "wait": 3,
  "dns": 10,
  "tcp": 196,
  "tls": 397,
  "request": 1,
  "firstByte": 200,
  "download": 4,
  "total": 811
}
{
  "wait": 3,
  "dns": 11,
  "tcp": 208,
  "tls": 407,
  "request": 0,
  "firstByte": 208,
  "download": 0,
  "total": 837
}

But, if I try to use the option --json to get the response in a easily parsed format, the output does not contain the responses from repeated requests. It only contains one response.

httpyac send post.http -n post --repeat 2 --repeat-mode serial --json > .\post-log.json

jq '.requests[].response.timings' .\post-log.json
{
  "wait": 2,
  "dns": 10,
  "tcp": 205,
  "tls": 407,
  "request": 0,
  "firstByte": 207,
  "download": 4,
  "total": 835
}

Note: the field is now named response and not responses

Also, with release 5.2.1 as fix for issue https://github.com/httpyac/httpyac.github.io/issues/34, fields count and statusCount were added to the summary. These are also lost if the formatting option --json is used.

AnWeber commented 1 year ago

@dinurp Actually, it already works as it is designed. The idea of repeat is to quickly send several requests at the same time and thus put the server under load. These are not treated as own requests, but are merged at the end in the body of the first request. In the JSON output, I output the body only as a string and these contain the timings that you are interested in. For this reason it would be better for you to simply use `--output body' here.

I noticed that the timings are not properly merged in the '--json' output . The root element contains only the first timings object. I change this and output the average. And additionally I make it possible that the timings are also output when using --output exchange or --output timings.

dinurp commented 1 year ago

Thanks for pointing me to the right direction. I see that I can get what I was looking for by parsing the body.

httpyac send post.http -n post--repeat 25 --json  > out.json
jq "[.requests[].response.body|fromjson|.responses[]|{statusCode,timings}]" out.json