cURL strange behaviour

This night I was struggling with cURL (directy from the CLI and mod_curl from php). I was trying to get the Content-Length of a static file to determine it’s filesize but I never saw the result on some objects.

poisonbook:data poison$ curl -I http://iscsi06/v/tt/001/123/1123081.jpg -H "Host: de.video.netlogstatic.com"
HTTP/1.1 200 OK
Expires: Sat, 14 Mar 2009 23:56:18 GMT
Cache-Control: max-age=2592000
Content-Type: image/jpeg
Accept-Ranges: bytes
Last-Modified: Wed, 06 Feb 2008 11:16:08 GMT
Date: Thu, 12 Feb 2009 23:56:18 GMT
Server: lighttpd/1.4.19

As you see, no Content-Length header in it. So I was thinking it’s a bug in lightty and I started to browse the forums. After a half an hour reading, testing, cursing and drinking beers I finally tried to do a manual HTTP request using telnet.

poisonbook:data poison$ telnet iscsi06 80
Trying 192.168.44.6...
Connected to iscsi06.
Escape character is '^]'.
GET /v/tt/001/123/1123081.jpg HTTP/1.1
Host: de.video.netlogstatic.com

HTTP/1.1 200 OK
Expires: Sat, 14 Mar 2009 23:57:00 GMT
Cache-Control: max-age=2592000
Content-Type: image/jpeg
Accept-Ranges: bytes
Last-Modified: Wed, 06 Feb 2008 11:16:08 GMT
Content-Length: 0
Date: Thu, 12 Feb 2009 23:57:00 GMT
Server: lighttpd/1.4.19

You can see, there IS a Content-Length header, but when it’s 0 cURL just ignores it!

Remember: Content-Length: 0 is as good as non-existant in cURL

The versions of cURL I used:

CLI: curl 7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 AND curl 7.15.5 (x86_64-pc-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8c zlib/1.2.3 libidn/0.6.5

PHP:     [version] => 7.15.5, [host] => x86_64-pc-linux-gnu, [ssl_version] =>  OpenSSL/0.9.8c, [libz_version] => 1.2.3

Cheers,
Nicolas

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image