DEV Community

Cover image for cURL Tips for Performance Engineers πŸ’«
NaveenKumar Namachivayam ⚑
NaveenKumar Namachivayam ⚑

Posted on • Originally published at qainsights.com

cURL Tips for Performance Engineers πŸ’«

In this blog post, we are going to see about CURL tips for performance engineers. I have already published a YouTube video about cURL for Performance Engineers. We are going to see a few more tips about cURL.

https://youtu.be/kH84nvC8qOk

Headers to cURL

If you want to convert the headers to cURL command, there are a couple of ways you can do it.

  • Clone this repository https://github.com/curl/h2c
  • Launch WSL for Windows terminal.
  • Store your headers in a file, e.g. example.com
GET / HTTP/1.1
Host: example.com

Then, issue the command ./h2c < example.com. Here is the output you will get:

curl --http1.1 --header Accept: --header User-Agent: https://example.com/

If you prefer the online version, you can check this URL https://curl.se/h2c/

The online version will send your crunched data and converted on the curl server.

If you want to see more options for ./h2c, issue ./h2c -h command.

h2c.pl [options] < file
 -a   Allow curl's default headers
 -d   Output man page HTML links after command line
 -h   Show short help
 -H   Output HTTP generated URLs instead
 -i   Ignore HTTP version
 --libcurl Output libcurl code instead
 -n   Output notes after command line
 -s   Use short command line options
 -v   Add a verbose option to the command line

Where do you get the valid headers?

You can copy and paste the request headers from the browser. Open your favorite browser and launch the Developer Tools and go to Network tab.

Select the request and navigate to the Request Headers section to copy the source format of the headers as shown below, and then save it as a file.

cURL Tips for Performance Engineers - Copy the request headers
cURL Tips for Performance Engineers - Copy the request headers

If you would like to copy the cURL command directly from the browser, you can right-click on the request where you can see the cURL options as shown below.

Copy options for cURL
Copy options for cURL

Click on copy as cURL(cmd).

If you would like to create a JMeter test plan, launch JMeter, go to Tool > Import from cURL and enter the command as shown below.

Create Test Plan from cURL in JMeter
Create Test Plan from cURL in JMeter

Click on Create Test Plan which will create an HTTP Request Sampler and the HTTP Header Manager element.

Conclusion

cURL is a great utility for a quick smoke test and for automating stuffs. In performance testing, you can create cURL commands directly from the browser, or from the request headers. In JMeter, you can createa test plan directly from the cURL command.

Discussion (1)