cURL Tips for Performance Engineers 💫
Tags: testing, performance, webperf, tutorial
Published: 2021-09-01 15:46:36

<!-- wp:paragraph -->
<p>In this blog post, we are going to see about CURL tips for performance engineers. I have already published a YouTube video about <a href="https://www.youtube.com/watch?v=kH84nvC8qOk" target="_blank" rel="noreferrer noopener">cURL for Performance Engineers</a>. We are going to see a few more tips about cURL.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://youtu.be/kH84nvC8qOk","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtu.be/kH84nvC8qOk
</div></figure>
<!-- /wp:embed -->

<!-- wp:generateblocks/headline {"uniqueId":"396b6396"} -->
<h2 class="gb-headline gb-headline-396b6396 gb-headline-text">Headers to cURL</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>If you want to convert the headers to cURL command, there are a couple of ways you can do it. </p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Clone this repository https://github.com/curl/h2c</li><li>Launch WSL for Windows terminal.</li><li>Store your headers in a file, e.g. example.com</li></ul>
<!-- /wp:list -->

<!-- wp:code -->
<pre class="wp-block-code"><code>GET / HTTP/1.1
Host: example.com</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Then, issue the command <code>./h2c &lt; example.com</code>. Here is the output you will get:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>curl --http1.1 --header Accept: --header User-Agent: https://example.com/</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>If you prefer the online version, you can check this URL https://curl.se/h2c/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The online version will send your crunched data and converted on the curl server.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you want to see more options for ./h2c, issue <code>./h2c -h</code> command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>h2c.pl &#91;options] &lt; 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</code></pre>
<!-- /wp:code -->

<!-- wp:generateblocks/headline {"uniqueId":"3d0354c2"} -->
<h2 class="gb-headline gb-headline-3d0354c2 gb-headline-text">Where do you get the valid headers?</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>You can copy and paste the request headers from the browser. Open your favorite browser and launch the <strong>Developer Tools </strong>and go to <strong>Network </strong>tab.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Select the request and navigate to the <strong>Request Headers</strong> section to copy the source format of the headers as shown below, and then save it as a file.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8599,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-13.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-13.png" alt="cURL Tips for Performance Engineers - Copy the request headers" class="wp-image-8599"/></a><figcaption>cURL Tips for Performance Engineers - Copy the request headers</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8600,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-14.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-14.png" alt="Copy options for cURL" class="wp-image-8600"/></a><figcaption>Copy options for cURL</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Click on <strong>copy as cURL(cmd)</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you would like to create a JMeter test plan, launch JMeter, go to <strong>Tool &gt; Import from cURL</strong> and enter the command as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8601,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-15.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-15.png" alt="Create Test Plan from cURL in JMeter" class="wp-image-8601"/></a><figcaption>Create Test Plan from cURL in JMeter</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Click on <strong>Create Test Plan</strong> which will create an <strong>HTTP Request Sampler</strong> and the <strong>HTTP Header Manager</strong> element.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"9aa64498"} -->
<h2 class="gb-headline gb-headline-9aa64498 gb-headline-text">Conclusion</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->