From ae7688f6a286f7a01d027edd8ae8f8c598996d96 Mon Sep 17 00:00:00 2001 From: ducng99 Date: Tue, 21 Jan 2025 01:08:08 +1300 Subject: [PATCH] test: add test for stripping out multiple redirect header sections --- tests/system/HTTP/CURLRequestTest.php | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 138b7eaa7cb2..bf4407a4c649 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -1313,4 +1313,50 @@ public function testHTTPversionAsString(): void $this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options); $this->assertSame(CURL_HTTP_VERSION_2_0, $options[CURLOPT_HTTP_VERSION]); } + + public function testRemoveMultipleRedirectHeaderSections(): void + { + $testBody = 'Hello world'; + + $output = "HTTP/1.1 301 Moved Permanently +content-type: text/html; charset=utf-8 +content-length: 211 +location: http://example.com +date: Mon, 20 Jan 2025 11:46:34 GMT +server: nginx/1.21.6 +vary: Origin\r\n\r\nHTTP/1.1 302 Found +content-type: text/html; charset=utf-8 +content-length: 211 +location: http://example.com +date: Mon, 20 Jan 2025 11:46:34 GMT +server: nginx/1.21.6 +vary: Origin\r\n\r\nHTTP/1.1 307 Temporary Redirect +content-type: text/html; charset=utf-8 +content-length: 211 +location: http://example.com +date: Mon, 20 Jan 2025 11:46:34 GMT +server: nginx/1.21.6 +vary: Origin\r\n\r\nHTTP/2 308 +content-type: text/html; charset=utf-8 +content-length: 211 +location: http://example.com +date: Mon, 20 Jan 2025 11:46:34 GMT +server: nginx/1.21.6 +vary: Origin\r\n\r\nHTTP/1.1 200 OK +content-type: text/html; charset=utf-8 +content-length: 211 +date: Mon, 20 Jan 2025 11:46:34 GMT +server: nginx/1.21.6 +vary: Origin\r\n\r\n" . $testBody; + + $this->request->setOutput($output); + + $response = $this->request->request('GET', 'http://example.com', [ + 'allow_redirects' => true, + ]); + + $this->assertSame(200, $response->getStatusCode()); + + $this->assertSame($testBody, $response->getBody()); + } }