File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 11
11
12
12
namespace CodeIgniter \HTTP ;
13
13
14
+ use InvalidArgumentException ;
15
+
14
16
/**
15
17
* An HTTP message
16
18
*
@@ -112,6 +114,13 @@ public function hasHeader(string $name): bool
112
114
*/
113
115
public function getHeaderLine (string $ name ): string
114
116
{
117
+ if ($ this ->hasMultipleHeaders ($ name )) {
118
+ throw new InvalidArgumentException (
119
+ 'The header " ' . $ name . '" already has multiple headers. '
120
+ . ' You cannot use getHeaderLine(). '
121
+ );
122
+ }
123
+
115
124
$ origName = $ this ->getHeaderName ($ name );
116
125
117
126
if (! array_key_exists ($ origName , $ this ->headers )) {
Original file line number Diff line number Diff line change @@ -355,4 +355,23 @@ public function testAppendHeaderWithMultipleHeaders(): void
355
355
356
356
$ this ->message ->appendHeader ('Set-Cookie ' , 'HttpOnly ' );
357
357
}
358
+
359
+ public function testGetHeaderLineWithMultipleHeaders (): void
360
+ {
361
+ $ this ->expectException (InvalidArgumentException::class);
362
+ $ this ->expectExceptionMessage (
363
+ 'The header "Set-Cookie" already has multiple headers. You cannot use getHeaderLine(). '
364
+ );
365
+
366
+ $ this ->message ->addHeader (
367
+ 'Set-Cookie ' ,
368
+ 'logged_in=no; Path=/ '
369
+ );
370
+ $ this ->message ->addHeader (
371
+ 'Set-Cookie ' ,
372
+ 'sessid=123456; Path=/ '
373
+ );
374
+
375
+ $ this ->message ->getHeaderLine ('Set-Cookie ' );
376
+ }
358
377
}
You can’t perform that action at this time.
0 commit comments