cURL and Squid

Yesterday I was attempting to use curl to import data into our development servers to load up lots of data for a demo, and my curl command kept spitting back an error.

HTTP/1.0 417 Expectation Failed
Server: squid/3.1.12
Mime-Version: 1.0
Date: Wed, 10 Dec 2014 13:50:35 GMT
Content-Type: text/html
Content-Length: 3688
X-Squid-Error: ERR_INVALID_REQ 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from localhost
Via: 1.0 localhost (squid/3.1.12)
Connection: close
....
<p>Some possible problems are:</p>
<ul>
<li><p>Missing or unknown request method.</p></li>
<li><p>Missing URL.</p></li>
<li><p>Missing HTTP Identifier (HTTP/1.0).</p></li>
<li><p>Request is too large.</p></li>
<li><p>Content-Length missing for POST or PUT requests.</p></li>
<li><p>Illegal character in hostname; underscores are not allowed.</p></li>
<li><p>HTTP/1.1 <q>Expect:</q> feature is being asked from an HTTP/1.0 software.</p></li>
</ul>
....
<div id="footer">
<p>Generated Wed, 10 Dec 2014 13:50:35 GMT by localhost (squid/3.1.12)</p>
<!-- ERR_INVALID_REQ -->
</div>
</body></html>

Sadly, I wasted time by not thoroughly reading the error message, as I was attempting to go too fast with the goal to get extra data loaded for the demo. Finally, after taking a look at it this morning with fresh eyes, I saw the error was coming from Squid, and was not a response from our development servers complaining about some misconfigured settings or bad data format.

Finding it was had to do with Squid on my local machine, I was able to find that Squid (v3.1) was returning a 417 status code when using cURL’s default header settings.

The fix when using v3.1 of Squid is to add the option -H “Expect:” to the curl command to take off the Expect header.

The better option, if you can manage it, is to upgrade past v3.1 of Squid to at least v3.2, which claims HTTP/1.1 support. More information about the HTTP/1.1 support of Squid can be found here: http://wiki.squid-cache.org/Features/HTTP11

—Proctor