Skip to content

Commit

Permalink
Merge branch 'wip-MDL-60161-34' of git://github.com/abgreeve/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_34_STABLE
  • Loading branch information
stronk7 committed Dec 18, 2017
2 parents b85ec90 + 5433968 commit fb7b015
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/filelib.php
Expand Up @@ -3031,7 +3031,6 @@ public function resetHeader() {
* 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)) {
Expand All @@ -3040,7 +3039,10 @@ public function setHeader($header) {
}
} 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;
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions lib/tests/filelib_test.php
Expand Up @@ -501,6 +501,21 @@ public function test_curl_proxybypass() {
$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');

Expand Down

0 comments on commit fb7b015

Please sign in to comment.