@@ -62,12 +62,12 @@ public function testAddMultiple() {
6262 public function testAddMultipleCommaHeader () {
6363 $ headers = new Headers (self ::HEADER_ARRAY );
6464 $ headers ->add (
65- "Cookie-set " ,
65+ "Set-Cookie " ,
6666 "language=en; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com " ,
6767 "id=123; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com httponly "
6868 );
6969 $ headerArray = $ headers ->asArray ();
70- $ cookie = explode ("\n" , $ headerArray ["Cookie-set " ]);
70+ $ cookie = explode ("\n" , $ headerArray ["Set-Cookie " ]);
7171 self ::assertContains ("language=en; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com " , $ cookie );
7272 self ::assertContains ("id=123; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com httponly " , $ cookie );
7373 }
@@ -115,15 +115,66 @@ public function testGetMultiple() {
115115 public function testGetMultipleCommas () {
116116 $ headers = new Headers (self ::HEADER_ARRAY );
117117 $ headers ->add (
118- "Cookie-set " ,
118+ "Set-Cookie " ,
119119 "language=en; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com " ,
120120 "id=123; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com httponly "
121121 );
122122 self ::assertEquals (
123123 "language=en; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com "
124124 . "\n"
125125 . "id=123; expires=Thu, 1-Jan-1970 00:00:00 UTC; path=/; domain=example.com httponly " ,
126- $ headers ->get ("Cookie-set " )
126+ $ headers ->get ("Set-Cookie " )
127+ );
128+ }
129+
130+ public function testAddMultipleSetCookieWithoutCommaPreservesSeparateLines ():void {
131+ $ headers = new Headers (self ::HEADER_ARRAY );
132+ $ headers ->add ("Set-Cookie " , "language=en; Path=/ " );
133+ $ headers ->add ("Set-Cookie " , "id=123; HttpOnly " );
134+
135+ self ::assertCount (5 , $ headers );
136+ self ::assertSame (
137+ "language=en; Path=/ \nid=123; HttpOnly " ,
138+ $ headers ->asArray ()["Set-Cookie " ]
139+ );
140+ }
141+
142+ public function testGetAllAggregatesValuesAcrossSeparateHeaderLines ():void {
143+ $ firstValue = "Digest realm= \"example.com \", qop= \"auth \"" ;
144+ $ secondValue = "Digest realm= \"api.example.com \", qop= \"auth-int \"" ;
145+ $ headers = new Headers (self ::HEADER_ARRAY );
146+ $ headers ->add ("WWW-Authenticate " , $ firstValue );
147+ $ headers ->add ("WWW-Authenticate " , $ secondValue );
148+
149+ self ::assertSame (
150+ [$ firstValue , $ secondValue ],
151+ $ headers ->getAll ("WWW-Authenticate " )
152+ );
153+ }
154+
155+ public function testAsArrayPreservesAllDuplicateSpecialCaseHeaderLines ():void {
156+ $ firstValue = "Digest realm= \"example.com \", qop= \"auth \"" ;
157+ $ secondValue = "Digest realm= \"api.example.com \", qop= \"auth-int \"" ;
158+ $ headers = new Headers (self ::HEADER_ARRAY );
159+ $ headers ->add ("WWW-Authenticate " , $ firstValue );
160+ $ headers ->add ("WWW-Authenticate " , $ secondValue );
161+
162+ self ::assertSame (
163+ $ firstValue . "\n" . $ secondValue ,
164+ $ headers ->asArray ()["WWW-Authenticate " ]
165+ );
166+ }
167+
168+ public function testAsArrayNestedPreservesAllDuplicateHeaderLineValues ():void {
169+ $ firstValue = "Digest realm= \"example.com \", qop= \"auth \"" ;
170+ $ secondValue = "Digest realm= \"api.example.com \", qop= \"auth-int \"" ;
171+ $ headers = new Headers (self ::HEADER_ARRAY );
172+ $ headers ->add ("WWW-Authenticate " , $ firstValue );
173+ $ headers ->add ("WWW-Authenticate " , $ secondValue );
174+
175+ self ::assertSame (
176+ [$ firstValue , $ secondValue ],
177+ $ headers ->asArray (true )["WWW-Authenticate " ]
127178 );
128179 }
129180
0 commit comments