MDL-42951 curl: Always keep the last headers of a request

This commit is contained in:
Frederic Massart
2013-12-02 10:55:57 +13:00
committed by Sam Hemelryk
parent ea04def291
commit 20f8cd8551
2 changed files with 84 additions and 8 deletions
+11 -8
View File
@@ -3082,6 +3082,10 @@ class curl {
* private callback function
* Formatting HTTP Response Header
*
* We only keep the last headers returned. For example during a redirect the
* redirect headers will not appear in {@link self::getResponse()}, if you need
* to use those headers, refer to {@link self::get_raw_response()}.
*
* @param resource $ch Apparently not used
* @param string $header
* @return int The strlen of the header
@@ -3090,15 +3094,17 @@ class curl {
$this->rawresponse[] = $header;
if (trim($header, "\r\n") === '') {
if ($this->responsefinished) {
// Multiple headers means redirect, keep just the latest one.
$this->response = array();
return strlen($header);
}
// This must be the last header.
$this->responsefinished = true;
}
if (strlen($header) > 2) {
if ($this->responsefinished) {
// We still have headers after the supposedly last header, we must be
// in a redirect so let's empty the response to keep the last headers.
$this->responsefinished = false;
$this->response = array();
}
list($key, $value) = explode(" ", rtrim($header, "\r\n"), 2);
$key = rtrim($key, ':');
if (!empty($this->response[$key])) {
@@ -3402,9 +3408,6 @@ class curl {
}
}
$this->responsefinished = false;
$this->response = array();
curl_setopt($curl, CURLOPT_URL, $redirecturl);
$ret = curl_exec($curl);