title: cURL hanging for 15 seconds when sending HEAD requests
body: <h2>Background</h2>
  <p>I've been timing some HTTP requests via the CLI using <code>time</code> and tools such as <code>wget</code> and <code>curl</code> as follows:</p>
  <p><code>/usr/bin/time -v wget --spider http://localhost/index</code><br />
  <code>/usr/bin/time -v curl http://localhost/index 2&gt;&amp;1 &gt; /dev/null</code></p>
  <p>What I noticed is that when using <code>curl</code>, I was getting similar response times as with <code>wget</code> only on the first request, and much lower times on subsequent requests, as if the responses to <code>curl</code> were served from cache and <code>wget</code> were not.</p>
  <p>After investigating I found out that when specifying <code>--spider</code>, <code>wget</code> issues a <code>HEAD</code> request as appended below which could explain why the cache is bypassed with <code>wget</code>:</p>
  <p><em>Request</em></p>
  <pre><code>HEAD /index HTTP/1.0
  User-Agent: Wget/1.12 (linux-gnu)
  Accept: */*
  Host: localhost
  Connection: Keep-Alive
  </code></pre>
  <p><em>Response</em></p>
  <pre><code>HTTP/1.1 200 OK
  Date: Mon, 28 Nov 2011 14:45:59 GMT
  Server: Apache/2.2.14 (Ubuntu)
  Content-Location: index.php
  Vary: negotiate,Accept-Encoding
  TCN: choice
  X-Powered-By: PHP/5.3.2-1ubuntu4.10
  Set-Cookie: SESS421aa90e079fa326b6494f812ad13e79=16oqmug3loekjlb1tlvmsrtcr2; expires=Wed, 21-Dec-2011 18:19:19 GMT; path=/
  Expires: Sun, 19 Nov 1978 05:00:00 GMT
  Last-Modified: Mon, 28 Nov 2011 14:45:59 GMT
  Cache-Control: store, no-cache, must-revalidate
  Cache-Control: post-check=0, pre-check=0
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=utf-8
  </code></pre>
  <p>Since I'm doing more advanced stuff (writing body and headers in separate files, posting data, saving cookie in jar...) I need to use <code>curl</code> instead of <code>wget</code>. Therefore I'm trying to emulate a <code>HEAD</code> request with <code>curl</code>.</p>
  <h2>Issue</h2>
  <p>I managed to send a <code>HEAD</code> request with <code>curl</code> as follows:</p>
  <p><code>curl &quot;http://localhost/index&quot; --request &quot;HEAD&quot; -H &quot;Connection: Keep-Alive&quot; -0</code></p>
  <p><em>Request</em></p>
  <pre><code>HEAD /index HTTP/1.0
  User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
  Host: localhost
  Accept: */*
  Connection: Keep-Alive
  </code></pre>
  <p><em>Response</em></p>
  <pre><code>HTTP/1.1 200 OK
  Date: Mon, 28 Nov 2011 15:44:02 GMT
  Server: Apache/2.2.14 (Ubuntu)
  Content-Location: index.php
  Vary: negotiate,Accept-Encoding
  TCN: choice
  X-Powered-By: PHP/5.3.2-1ubuntu4.10
  Set-Cookie: SESS421aa90e079fa326b6494f812ad13e79=4001hcmhdbnkb9e2v8nok9lii1; expires=Wed, 21-Dec-2011 19:17:22 GMT; path=/
  Expires: Sun, 19 Nov 1978 05:00:00 GMT
  Last-Modified: Mon, 28 Nov 2011 15:44:02 GMT
  Cache-Control: store, no-cache, must-revalidate
  Cache-Control: post-check=0, pre-check=0
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=utf-8
  </code></pre>
  <p>Despite the request/response being seemingly OK, when I execute the above <code>curl</code> command while sniffing with <code>tcpdump</code> I can see that the server responds straight away, however <em>my <code>curl</code> command always stays hanging for exactly 15 seconds</em> which is obviously a big issue since I'm trying to time my <code>curl</code> command (FYI before I used to get a <code>curl: (18) transfer closed with 3 bytes remaining to read</code> when the server was not handling <code>HEAD</code> properly and was returning <code>Content-Length: 3</code> without returning any content, but no everything looks OK).</p>
  <p>I tried to play with the <code>--max-time</code> and <code>--speed-time</code> arguments to have <code>curl</code> timeout immediately upon receiving the <code>200 OK</code> but it makes no difference.</p>
  <p><strong>Q: How can I send a <code>HEAD</code> request with curl in a way that the curl command stops immediately upon receiving the response from the server?</strong></p>