Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support HAR files as input #285

Merged
merged 4 commits into from
Sep 30, 2020
Merged

feat: support HAR files as input #285

merged 4 commits into from
Sep 30, 2020

Conversation

feugy
Copy link
Contributor

@feugy feugy commented Sep 29, 2020

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:

node autocannon --har ./test/fixtures/httpbin-get.har -d 3 https://httpbin.org

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:

node autocannon --har test.har -d 3 -j https://nodejs.org

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 the tests/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.

lib/parseHAR.js Outdated Show resolved Hide resolved
test/run.test.js Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Owner

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
Copy link
Owner

Can you please update the PR text saying that it implements #185?

Copy link
Owner

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit eb60fff into mcollina:master Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session recording / HAR support
2 participants