Commit 18aaf112 authored by Dries's avatar Dries
Browse files

- Patch #50912 by eberts: HTTP request overrides headers and data on redirect.

parent 9e7ecfa1
...@@ -366,20 +366,20 @@ function drupal_http_request($url, $headers = array(), $method = 'GET', $data = ...@@ -366,20 +366,20 @@ function drupal_http_request($url, $headers = array(), $method = 'GET', $data =
// Fetch response. // Fetch response.
$response = ''; $response = '';
while (!feof($fp) && $data = fread($fp, 1024)) { while (!feof($fp) && $chunk = fread($fp, 1024)) {
$response .= $data; $response .= $chunk;
} }
fclose($fp); fclose($fp);
// Parse response. // Parse response.
list($headers, $result->data) = explode("\r\n\r\n", $response, 2); list($split, $result->data) = explode("\r\n\r\n", $response, 2);
$headers = preg_split("/\r\n|\n|\r/", $headers); $split = preg_split("/\r\n|\n|\r/", $split);
list($protocol, $code, $text) = explode(' ', trim(array_shift($headers)), 3); list($protocol, $code, $text) = explode(' ', trim(array_shift($split)), 3);
$result->headers = array(); $result->headers = array();
// Parse headers. // Parse headers.
while ($line = trim(array_shift($headers))) { while ($line = trim(array_shift($split))) {
list($header, $value) = explode(':', $line, 2); list($header, $value) = explode(':', $line, 2);
if (isset($result->headers[$header]) && $header == 'Set-Cookie') { if (isset($result->headers[$header]) && $header == 'Set-Cookie') {
// RFC 2109: the Set-Cookie response header comprises the token Set- // RFC 2109: the Set-Cookie response header comprises the token Set-
...@@ -1337,4 +1337,4 @@ function page_set_cache() { ...@@ -1337,4 +1337,4 @@ function page_set_cache() {
} }
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment