@@ -71,4 +71,41 @@ public function testLoadCookies()
7171 (yield $ jar ->get ((new Request ('http://127.0.0.1/ ' ))->getUri ()))[0 ]->getValue ()
7272 );
7373 }
74+
75+ public function testLoadHttpOnlyCookies ()
76+ {
77+ $ expire = (new DateTimeImmutable ())->modify ('+1 day ' )->format ('U ' );
78+
79+ $ cookies = <<<EOT
80+ # Netscape HTTP Cookie File
81+ # This is a comment and should be ignored
82+
83+ #HttpOnly_.example.com TRUE / FALSE $ expire session_id abc123
84+ #HttpOnly_example.com FALSE /admin TRUE $ expire admin_token xyz789
85+ .example.com TRUE / FALSE $ expire regular_cookie normal_value
86+ EOT
87+ ;
88+
89+ $ this ->workspace ()->put ('httponly_cookies.txt ' , $ cookies );
90+ $ path = $ this ->workspace ()->path ('httponly_cookies.txt ' );
91+
92+ $ jar = new NetscapeCookieFileJar ($ path );
93+
94+ $ allCookies = $ jar ->getAll ();
95+
96+ // Should have 3 cookies total (2 httponly + 1 regular)
97+ $ this ->assertCount (3 , $ allCookies );
98+
99+ // Get cookies for example.com
100+ $ exampleCookies = yield $ jar ->get ((new Request ('https://example.com/ ' ))->getUri ());
101+
102+ // Should include the httponly cookie
103+ $ cookieNames = array_map (fn ($ cookie ) => $ cookie ->getName (), $ exampleCookies );
104+ $ this ->assertContains ('session_id ' , $ cookieNames );
105+ $ this ->assertContains ('regular_cookie ' , $ cookieNames );
106+
107+ // Verify httponly cookie value
108+ $ sessionCookie = array_filter ($ exampleCookies , fn ($ cookie ) => $ cookie ->getName () === 'session_id ' );
109+ $ this ->assertEquals ('abc123 ' , reset ($ sessionCookie )->getValue ());
110+ }
74111}
0 commit comments