@@ -31,17 +31,10 @@ public function __construct(ReadableStreamInterface $stream, $protocol, $version
3131 $ this ->code = $ code ;
3232 $ this ->reasonPhrase = $ reasonPhrase ;
3333 $ this ->headers = $ headers ;
34- $ normalizedHeaders = array_change_key_case ($ headers , CASE_LOWER );
3534
36- if (isset ( $ normalizedHeaders [ ' transfer-encoding ' ]) && strtolower ( $ normalizedHeaders [ ' transfer-encoding ' ] ) === 'chunked ' ) {
35+ if (strtolower ( $ this -> getHeaderLine ( ' Transfer-Encoding ' ) ) === 'chunked ' ) {
3736 $ this ->stream = new ChunkedStreamDecoder ($ stream );
38-
39- foreach ($ this ->headers as $ key => $ value ) {
40- if (strcasecmp ('transfer-encoding ' , $ key ) === 0 ) {
41- unset($ this ->headers [$ key ]);
42- break ;
43- }
44- }
37+ $ this ->removeHeader ('Transfer-Encoding ' );
4538 }
4639
4740 $ this ->stream ->on ('data ' , array ($ this , 'handleData ' ));
@@ -75,6 +68,29 @@ public function getHeaders()
7568 return $ this ->headers ;
7669 }
7770
71+ private function removeHeader ($ name )
72+ {
73+ foreach ($ this ->headers as $ key => $ value ) {
74+ if (strcasecmp ($ name , $ key ) === 0 ) {
75+ unset($ this ->headers [$ key ]);
76+ break ;
77+ }
78+ }
79+ }
80+
81+ private function getHeader ($ name )
82+ {
83+ $ name = strtolower ($ name );
84+ $ normalized = array_change_key_case ($ this ->headers , CASE_LOWER );
85+
86+ return isset ($ normalized [$ name ]) ? (array )$ normalized [$ name ] : array ();
87+ }
88+
89+ private function getHeaderLine ($ name )
90+ {
91+ return implode (', ' , $ this ->getHeader ($ name ));
92+ }
93+
7894 /** @internal */
7995 public function handleData ($ data )
8096 {
0 commit comments