Merge branch 'wip-MDL-60161-master-test' of git://github.com/abgreeve/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2017-12-18 16:09:51 +01:00
commit 6663f615ed
2 changed files with 19 additions and 2 deletions

View File

@ -3031,7 +3031,6 @@ class curl {
* Set HTTP Request Header
*
* @param array $header
* @param bool $replace If true, will remove any existing headers before appending the new one.
*/
public function setHeader($header) {
if (is_array($header)) {
@ -3040,7 +3039,10 @@ class curl {
}
} else {
// Remove newlines, they are not allowed in headers.
$this->header[] = preg_replace('/[\r\n]/', '', $header);
$newvalue = preg_replace('/[\r\n]/', '', $header);
if (!in_array($newvalue, $this->header)) {
$this->header[] = $newvalue;
}
}
}

View File

@ -501,6 +501,21 @@ class core_filelib_testcase extends advanced_testcase {
$CFG->proxybypass = $oldproxybypass;
}
/**
* Test that duplicate lines in the curl header are removed.
*/
public function test_duplicate_curl_header() {
$testurl = $this->getExternalTestFileUrl('/test_post.php');
$curl = new curl();
$headerdata = 'Accept: application/json';
$header = [$headerdata, $headerdata];
$this->assertCount(2, $header);
$curl->setHeader($header);
$this->assertCount(1, $curl->header);
$this->assertEquals($headerdata, $curl->header[0]);
}
public function test_curl_post() {
$testurl = $this->getExternalTestFileUrl('/test_post.php');