@@ -31,17 +31,10 @@ public function __construct(ReadableStreamInterface $stream, $protocol, $version
31
31
$ this ->code = $ code ;
32
32
$ this ->reasonPhrase = $ reasonPhrase ;
33
33
$ this ->headers = $ headers ;
34
- $ normalizedHeaders = array_change_key_case ($ headers , CASE_LOWER );
35
34
36
- if (isset ( $ normalizedHeaders [ ' transfer-encoding ' ]) && strtolower ( $ normalizedHeaders [ ' transfer-encoding ' ] ) === 'chunked ' ) {
35
+ if (strtolower ( $ this -> getHeaderLine ( ' Transfer-Encoding ' ) ) === 'chunked ' ) {
37
36
$ 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 ' );
45
38
}
46
39
47
40
$ this ->stream ->on ('data ' , array ($ this , 'handleData ' ));
@@ -75,6 +68,29 @@ public function getHeaders()
75
68
return $ this ->headers ;
76
69
}
77
70
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
+
78
94
/** @internal */
79
95
public function handleData ($ data )
80
96
{
0 commit comments