mcollina / autocannon

fast HTTP/1.1 benchmarking tool written in Node.js
MIT License
7.76k stars 322 forks source link

Feature: adding the whole response to verifyBody callback #487

Open moty66 opened 1 year ago

moty66 commented 1 year ago

For money reasons, it will be useful to access the original request and the whole response when verifying the body

const isFn = typeof this.opts.verifyBody === 'function'
if (isFn && !this.opts.verifyBody(resp.body)) {
  return this.emit('mismatch', resp.body)
} else if (!isFn && this.opts.expectBody && this.opts.expectBody !== resp.body) {
  return this.emit('mismatch', resp.body)
}

I think adding a second parameter to the callback verifyBody(resp.body, resp) will not break anything and will be useful for advanced body verifications

Can I make a pull request for this feature

GlenTiki commented 1 year ago

I think this should be doable but you’ll need to write a few in-depth test cases to verify edge cases, specifically if you verify the response asynchronously (think in a process.nextTick). I’m unsure of the object referenced stability where request object’s are reused for efficient execution, but it’s worth a try.