1
0
mirror of https://github.com/moodle/moodle.git synced 2025-02-17 14:25:37 +01:00

Merge branch 'MDL-72349_update_strip_double_headers_function' of https://github.com/christina-roperto/moodle

This commit is contained in:
Andrew Nicols 2022-07-29 12:11:22 +08:00
commit b47fcbb204
2 changed files with 151 additions and 2 deletions

@ -4201,14 +4201,14 @@ class curl {
$crlf = "\r\n";
return preg_replace(
// HTTP version and status code (ignore value of code).
'~^HTTP/1\..*' . $crlf .
'~^HTTP/[1-9](\.[0-9])?.*' . $crlf .
// Header name: character between 33 and 126 decimal, except colon.
// Colon. Header value: any character except \r and \n. CRLF.
'(?:[\x21-\x39\x3b-\x7e]+:[^' . $crlf . ']+' . $crlf . ')*' .
// Headers are terminated by another CRLF (blank line).
$crlf .
// Second HTTP status code, this time must be 200.
'(HTTP/1.[01] 200 )~', '$1', $input);
'(HTTP/[1-9](\.[0-9])? 200)~', '$2', $input);
}
}

@ -976,6 +976,155 @@ EOF;
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/1.0 200 Connection established
HTTP/2 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
$httpsexpected = <<<EOF
HTTP/2 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
// For HTTP, replace the \n with \r\n.
$httpsexample = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexample);
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/1.0 200 Connection established
HTTP/2.1 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
$httpsexpected = <<<EOF
HTTP/2.1 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
// For HTTP, replace the \n with \r\n.
$httpsexample = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexample);
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/1.1 200 Connection established
HTTP/3 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
$httpsexpected = <<<EOF
HTTP/3 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
// For HTTP, replace the \n with \r\n.
$httpsexample = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexample);
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/2 200 Connection established
HTTP/4 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
$httpsexpected = <<<EOF
HTTP/4 200 OK
Date: Fri, 22 Feb 2013 17:14:23 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.3-7+squeeze14
Content-Type: text/xml
Connection: close
Content-Encoding: gzip
Transfer-Encoding: chunked
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">...
EOF;
// For HTTP, replace the \n with \r\n.
$httpsexample = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexample);
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
}
/**