Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's in there?
This PR allow CLI users to speciffy
--har
options with the path to an.har
file.Requests from the har will be fired against the specify server.
Please note that Autocannon will ignore HAR requests that would not match the domain of your URL.
This is because each httpClient handles the connection to a single domain. It is not possible for a client to switch to a different one, based on current request.
How to test?
You can use any of the test fixtures:
You can also record an .har from your favorite browser's dev tools.
For example, with you devtools opened, go the node.js reference. A couple of requests will appear on network tab.
Export them as an HAR file, and try playing it again:
Please note that some request may "fail" with "3xx" statuses.
Finally, it is possible to specify
har
option when using the programmatic API, as demonstrated in thetests/run.test.js
file.Notes to reviewers
HAR files are plain JSON files, and there is no need for a specific parser, in particular because we're using a tiny part of the file (we ignore pages, responses, timing...)
parseHAR.js
file is exposing functions to read and parse files in a synchronous or asynchronous fashion. However, it made little sense to use the asynchronous flavor: HAR parsing occurs only once, before starting benchmark, and that part of Autocannon code if synchronous.Changing it to asynchronous would be a major change for little-to-no benefit (in my opinion).
there could be more checks on the HAR content (I assumed that requests will contain the proper keys), and I'm happy to add more if you think it worth it.