The problem is that the function accepts the parameters $headers, $data and some others.
and the same variables $headers and $data get overwritten within the function here
data) = explode("\r\n\r\n", $response, 2); // <- HERE $headers
$headers = preg_split("/\r\n|\n|\r/", $headers); // <- HERE $headers
list($protocol, $code, $text) = explode(' ', trim(array_shift($headers)), 3);
$result->headers = array();
// Parse headers.
while ($line = trim(array_shift($headers))) {
...
?>
then there is the check for the response code and if it is 301, 302, 307 it redirects by recursively calling drupal_http_request()
again with the parameters $headers and $data wich are no longer valid because they got overwritten.
headers['Location'];
if ($retry) {
$result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry); // <- HERE is the call
$result->redirect_code = $result->code;
}
$result->redirect_url = $location;
break;
default:
$result->error = $text;
}
?>