bench-rest
bench-rest copied to clipboard
Https examples please?
Hello,
This project claims that it is a benchmark solution for both http and https. Would you be so kind to provide an example including authorization ? I'm trying to use Hawk authorization and I can't see how or where I can inject the required headers, which requires recalculation on each request.
Regards
Yes, you can easily modify the request headers using the beforeHooks. You would modify the all.requestOptions
object specifically the headers
property of all.requestOptions
. It accepts anything that request
takes https://github.com/request/request#readme
I'm not that familiar with Hawk, but from looking at the example your code would be something like this.
const Hawk = require('hawk');
const credentials = {
id: 'dh37fgj492je',
key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
algorithm: 'sha256'
};
var flow = {
before: [], // operations to do before anything
beforeMain: [], // operations to do before each iteration
main: [ // the main flow for each iteration, #{INDEX} is unique iteration counter token
{
post: 'https://myserver/',
json: { foo: 'bar' },
beforeHooks: [
function (all) {
const currentURI = all.requestOptions.uri;
var payloadObj = all.requestOptions.json;
const header = Hawk.client.header(currentURI, 'POST', { credentials: credentials, payload: JSON.stringify(payloadObj), });
all.requestOptions.headers = {
Authorization = header.field
};
return all; // always return all if you want it to continue
}
]
}
],
afterMain: [], // operations to do after each iteration
after: [] // operations to do after everything is done
};
module.exports = flow;
Hello @jeffbski
Thank you very much for tour detailed answer!! May I ask if making the authorization on the beforeRequest adds delay? Well, it will of course, what I mean if that delay will be counted as part of the request so the impact is reflected on the summary or not. What I'm doing right now is authorizing all the request before even starting the bench test. Do you see any problem in my approach?
Yes, you should only need to auth at the beginning of each flow. Each iteration will contain its own cookie jar so it won't conflict with other concurrent iterations. Any code that you run will add to the total iteration time, but I doubt that it would influence it much unless Hawk is unusually slow.