autocannon
autocannon copied to clipboard
cURL parameter compatibility
Hi! To use autocannon, I commonly follow the steps:
- invokes the endpoint with a cURL, adjusting the input parameters and checking the response
- convert every cURL parameters into autocannon ones
- invokes the endpoint with autocannon with
-a 1 -c 1
and see if the status code is 200 (hoping the response body is the same) - invokes the endpoint with autocannon with parameters for load test
Unfortunately, the parameter conversion is not easy, and step 3 requires more retries.
My desiderata would be to replace the cURL
command with autocannon
without parameter conversion.
In this way, we can remove some pains during the tests.
Other considerations:
- Another path I commonly take is to copy the cURL directly from the browser network tab.
- We can start from the common cURL parameters like header and request body.
I can take this by providing a PR if you are interested in this enhancement, but please give me some input on where to start.
What do you think?
That's what would need to be changed: https://github.com/mcollina/autocannon/blob/ac8169cd7f1161c127d7554900ebefff89b8baee/autocannon.js#L107-L116.
I would also recommend to modernize this using node core utility for parsing arguments.
Is it ok for you having a breaking change with the cli ?
If we can support commands (as aliases) that would be great. If not I'm happy to support the brekage, but I would like to see the impact before confirming.
I had a parameters review. Some conflicts would be excellent to resolve somehow. Here is a recap below:
-
--data
is used to send the request body. Nowautocannon
only handles-b
, so I added it as an alias - if the request body is present, the request method is set to POST if not explicitly given. I put the method to POST if
body
is given. breaking change -
-v
puts the curl in debug mode, dumping the request (whole request, not just the body) and the response (whole response, not just the body). Instead,autocannon
uses this parameter as an alias of--version
. breaking change -
--data @filepath
is not supported by autocannon. possible breaking change -
-X
is used to specify the http request method. I put it as an alias - I don't want to support
--location
because it could be hard to implement. Anyway,autocannon
ignores unknown parameters, so it is okay. - By default,
--data
putsapplication/x-www-form-urlencoded
as the content type. -
--data
if read from a file, remove all the\n
and similar stuff. -
--data-binary
sends the data as is without removing\n
and similar stuff.
Considering the above list, I see two ways to avoid a breaking change:
a. use a different node bin, like autocannon-curl
b. put a --curl-compatibility
(or similar) parameter to tell autocannon to parse the parameters as curl
-like params.
c. put a --from-curl-command
parameter to tell the rest of the strings are a curl command. Just an example autocannon -c 10 -d 10 --from-curl-command curl -X POST -d @foo "https://httpbin.org/anything" -H "accept: application/json"
. This will used the parameters before the --from-curl-command
as autocannon parameters, the after ones as curl parameters.
I also started the implementation. If you are interested, I'll also open a PR!
Let me know how you prefer to proceed.
I don't see any major disruption here. I'm ok to ship a major with those changes.