2929 */
3030final class CURLRequestTest extends CIUnitTestCase
3131{
32- private CURLRequest $ request ;
32+ private MockCURLRequest $ request ;
3333
3434 protected function setUp (): void
3535 {
@@ -39,7 +39,7 @@ protected function setUp(): void
3939 $ this ->request = $ this ->getRequest ();
4040 }
4141
42- protected function getRequest (array $ options = [])
42+ protected function getRequest (array $ options = []): MockCURLRequest
4343 {
4444 $ uri = isset ($ options ['base_uri ' ]) ? new URI ($ options ['base_uri ' ]) : new URI ();
4545 $ app = new App ();
@@ -205,7 +205,7 @@ public function testOptionsHeadersNotUsingPopulate(): void
205205 $ this ->assertSame ('' , $ request ->header ('Accept-Encoding ' )->getValue ());
206206 }
207207
208- public function testOptionsAreSharedBetweenRequests (): void
208+ public function testDefaultOptionsAreSharedBetweenRequests (): void
209209 {
210210 $ options = [
211211 'form_params ' => ['studio ' => 1 ],
@@ -868,6 +868,38 @@ public function testResponseHeadersWithMultipleRequests(): void
868868 $ this ->assertSame (200 , $ response ->getStatusCode ());
869869 }
870870
871+ public function testResponseHeadersWithMultipleSetCookies (): void
872+ {
873+ $ request = $ this ->getRequest ([
874+ 'base_uri ' => 'https://github.com/ ' ,
875+ ]);
876+
877+ $ output = "HTTP/2 200
878+ server: GitHub.com
879+ date: Sat, 11 Nov 2023 02:26:55 GMT
880+ content-type: text/html; charset=utf-8
881+ set-cookie: _gh_sess=PlRlha1YumlLhLuo5MuNbIWJRO9RRuR%2FHfYsWRh5B0mkalFIZstlAbTmSstl8q%2FAC57IsWMVuFHWQc6L4qDHQJrwhuYVO5ZaigPCUjAStnhh%2FieZQVqIf92Al7vusuzx2o8XH%2Fv6nd9qzMTAWc2%2FkRsl8jxPQYGNaWeuUBY2w3%2FDORSikN4c0vHOyedhU7Xcv3Ryz5xD3DNxK9R8xKNZ6OSXLJ6bjX8iIT6LxvroVIf2HjvowW9cQsq0kN08mS6KtTnH0mD3ANWqsVVWeMzFNA%3D%3D--Jx830Q9Nmkfz9OGA--kEcPtNphvjNMopYqFDxUbw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
882+ set-cookie: _octo=GH1.1.599292127.1699669625; Path=/; Domain=github.com; Expires=Mon, 11 Nov 2024 02:27:05 GMT; Secure; SameSite=Lax
883+ set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Mon, 11 Nov 2024 02:27:05 GMT; HttpOnly; Secure; SameSite=Lax
884+ accept-ranges: bytes \x0d\x0a\x0d\x0a" ;
885+ $ request ->setOutput ($ output );
886+
887+ $ response = $ request ->get ('/ ' );
888+
889+ $ setCookieHeaders = $ response ->header ('set-cookie ' );
890+
891+ $ this ->assertCount (3 , $ setCookieHeaders );
892+ $ this ->assertSame (
893+ 'logged_in=no; Path=/; Domain=github.com; Expires=Mon, 11 Nov 2024 02:27:05 GMT; HttpOnly; Secure; SameSite=Lax ' ,
894+ $ setCookieHeaders [2 ]->getValue ()
895+ );
896+
897+ $ this ->assertSame (
898+ '_octo=GH1.1.599292127.1699669625; Path=/; Domain=github.com; Expires=Mon, 11 Nov 2024 02:27:05 GMT; Secure; SameSite=Lax ' ,
899+ $ setCookieHeaders [1 ]->getValueLine ()
900+ );
901+ }
902+
871903 public function testSplitResponse (): void
872904 {
873905 $ request = $ this ->getRequest ([
@@ -1026,6 +1058,10 @@ public function testJSONData(): void
10261058 $ this ->assertSame ('POST ' , $ this ->request ->getMethod ());
10271059
10281060 $ expected = json_encode ($ params );
1061+ $ this ->assertSame (
1062+ $ expected ,
1063+ $ this ->request ->curl_options [CURLOPT_POSTFIELDS ]
1064+ );
10291065 $ this ->assertSame ($ expected , $ this ->request ->getBody ());
10301066 }
10311067
@@ -1040,7 +1076,13 @@ public function testSetJSON(): void
10401076 ];
10411077 $ this ->request ->setJSON ($ params )->post ('/post ' );
10421078
1043- $ this ->assertSame (json_encode ($ params ), $ this ->request ->getBody ());
1079+ $ expected = json_encode ($ params );
1080+ $ this ->assertSame (
1081+ $ expected ,
1082+ $ this ->request ->curl_options [CURLOPT_POSTFIELDS ]
1083+ );
1084+ $ this ->assertSame ($ expected , $ this ->request ->getBody ());
1085+
10441086 $ this ->assertSame (
10451087 'Content-Type: application/json ' ,
10461088 $ this ->request ->curl_options [CURLOPT_HTTPHEADER ][0 ]
@@ -1137,4 +1179,21 @@ public function testMultipleHTTP100(): void
11371179
11381180 $ this ->assertSame (200 , $ response ->getStatusCode ());
11391181 }
1182+
1183+ public function testGetHeaderLineContentType (): void
1184+ {
1185+ $ output = 'HTTP/2 200
1186+ date: Thu, 11 Apr 2024 07:26:00 GMT
1187+ content-type: text/html; charset=UTF-8
1188+ cache-control: no-store, max-age=0, no-cache
1189+ server: cloudflare
1190+ content-encoding: br
1191+ alt-svc: h3=":443"; ma=86400 ' . "\x0d\x0a\x0d\x0aResponse Body " ;
1192+
1193+ $ this ->request ->setOutput ($ output );
1194+
1195+ $ response = $ this ->request ->request ('get ' , 'http://example.com ' );
1196+
1197+ $ this ->assertSame ('text/html; charset=UTF-8 ' , $ response ->getHeaderLine ('Content-Type ' ));
1198+ }
11401199}
0 commit comments