Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.896
diff -u -9 -p -r1.896 common.inc
--- includes/common.inc	9 May 2009 18:39:03 -0000	1.896
+++ includes/common.inc	9 May 2009 20:29:37 -0000
@@ -516,27 +516,34 @@ function drupal_http_request($url, array
     'headers' => array(),
     'method' => 'GET',
     'data' => NULL,
     'max_redirects' => 3,
   );
 
   // Merge the default headers.
   $options['headers'] += array(
     'User-Agent' => 'Drupal (+http://drupal.org/)',
-    'Content-Length' => strlen($options['data']),
   );
 
   // RFC 2616: "non-standard ports MUST, default ports MAY be included".
   // We don't add the standard port to prevent from breaking rewrite rules
   // checking the host that do not take into account the port number.
   $options['headers']['Host'] = $host;
 
-  // If the server url has a user then attempt to use basic authentication
+  // Only add Content-Length if we actually have any content or if it is a POST
+  // or PUT request. Some non-standard servers get confused by Content-Length in
+  // at least HEAD/GET requests, and Squid always requires Content-Length in
+  // POST/PUT requests.
+  if (!empty($options['data']) || $options['method'] == 'POST' || $options['method'] == 'PUT') {
+    $options['headers']['Content-Length'] = strlen($options['data']);
+  }
+
+  // If the server URL has a user then attempt to use basic authentication.
   if (isset($uri['user'])) {
     $options['headers']['Authorization'] = 'Basic ' . base64_encode($uri['user'] . (!empty($uri['pass']) ? ":" . $uri['pass'] : ''));
   }
 
   // If the database prefix is being used by SimpleTest to run the tests in a copied
   // database then set the user-agent header to the database prefix so that any
   // calls to other Drupal pages will run the SimpleTest prefixed database. The
   // user-agent is used to ensure that multiple testing sessions running at the
   // same time won't interfere with each other as they would if the database
