File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1111
1212namespace CodeIgniter \HTTP ;
1313
14+ use InvalidArgumentException ;
15+
1416/**
1517 * An HTTP message
1618 *
@@ -112,6 +114,13 @@ public function hasHeader(string $name): bool
112114 */
113115 public function getHeaderLine (string $ name ): string
114116 {
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+
115124 $ origName = $ this ->getHeaderName ($ name );
116125
117126 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
355355
356356 $ this ->message ->appendHeader ('Set-Cookie ' , 'HttpOnly ' );
357357 }
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+ }
358377}
You can’t perform that action at this time.
0 commit comments