You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is intended behavior or a bug, but in the setupClient, while doing a client.setHeaders, it only affects the first request in the requests array.
Example:
'use strict'constautocannon=require('autocannon')autocannon({url: `https://example.com`,connections: 1,duration: 1,amount: 1,setupClient: (client)=>{constuserInfo=getNextUserInfo()// I expect this to set the headers for all requests in the list belowclient.setHeaders({'Authorization': userInfo.authorizationToken,'Content-Type': 'application/json',})},requests: [{path: `/someEndpoint`,method: 'POST',setupRequest: (req,context)=>{// I do this hack to get the headers forwarded to the next request;// context.authHeaders = req.headers // left out to show bugreturn{
...req,body: JSON.stringify({command: 'startTournamentLevel',}),}},onResponse: (status,body,context)=>{if(status===200){context.data=JSON.parse(body)}},},{path: `/someOtherEndpoint`,method: 'POST',setupRequest: (req,context)=>{console.log('req.headers is not set',JSON.stringify(req.headers))return{
...req,// headers: context.authHeaders, // I do this hack to get the headers forwarded. Left out to expose bugbody: JSON.stringify({someData: context.data.some,}),}},}],},console.log)
I think I have found the reason in the source code;
The method on the httpClient passes the to the requestIterator
I'm not sure what is the correct behavior, but I would expect that perhaps the httpClient saved the headers, and added it to all requests as the new default.
Again, not sure if it is a bug, but it feels like it. I was able to work around it by adding the headers to the context object on the first request, in case anyone else has this issue.
The text was updated successfully, but these errors were encountered:
I'm not sure if this is intended behavior or a bug, but in the
setupClient
, while doing aclient.setHeaders
, it only affects the first request in therequests
array.Example:
I think I have found the reason in the source code;
The method on the
httpClient
passes the to the requestIteratorautocannon/lib/httpClient.js
Line 211 in 5364353
It seems this method only sets the headers for the
currentRequest
autocannon/lib/requestIterator.js
Line 54 in 5364353
I'm not sure what is the correct behavior, but I would expect that perhaps the
httpClient
saved the headers, and added it to all requests as the new default.Again, not sure if it is a bug, but it feels like it. I was able to work around it by adding the headers to the context object on the first request, in case anyone else has this issue.
The text was updated successfully, but these errors were encountered: