@@ -113,19 +113,14 @@ public function sendRequest(RequestInterface $request)
113
113
114
114
$ headerSize = $ info ['header_size ' ];
115
115
$ rawHeaders = substr ($ raw , 0 , $ headerSize );
116
+ $ headers = $ this ->parseRawHeaders ($ rawHeaders );
116
117
117
- // Parse headers
118
- $ allHeaders = explode ("\r\n\r\n" , $ rawHeaders );
119
- $ lastHeaders = trim (array_pop ($ allHeaders ));
120
- while (count ($ allHeaders ) > 0 && '' === $ lastHeaders ) {
121
- $ lastHeaders = trim (array_pop ($ allHeaders ));
122
- }
123
- $ headerLines = explode ("\r\n" , $ lastHeaders );
124
- foreach ($ headerLines as $ header ) {
118
+ foreach ($ headers as $ header ) {
125
119
$ header = trim ($ header );
126
120
if ('' === $ header ) {
127
121
continue ;
128
122
}
123
+
129
124
// Status line
130
125
if (substr (strtolower ($ header ), 0 , 5 ) === 'http/ ' ) {
131
126
$ parts = explode (' ' , $ header , 3 );
@@ -134,6 +129,7 @@ public function sendRequest(RequestInterface $request)
134
129
->withProtocolVersion (substr ($ parts [0 ], 5 ));
135
130
continue ;
136
131
}
132
+
137
133
// Extract header
138
134
$ parts = explode (': ' , $ header , 2 );
139
135
$ headerName = trim (urldecode ($ parts [0 ]));
@@ -290,4 +286,22 @@ private function createHeaders(RequestInterface $request, array $options)
290
286
}
291
287
return $ curlHeaders ;
292
288
}
289
+
290
+ /**
291
+ * Parse raw headers from HTTP response
292
+ *
293
+ * @param string $rawHeaders
294
+ *
295
+ * @return string[]
296
+ */
297
+ private function parseRawHeaders ($ rawHeaders )
298
+ {
299
+ $ allHeaders = explode ("\r\n\r\n" , $ rawHeaders );
300
+ $ lastHeaders = trim (array_pop ($ allHeaders ));
301
+ while (count ($ allHeaders ) > 0 && '' === $ lastHeaders ) {
302
+ $ lastHeaders = trim (array_pop ($ allHeaders ));
303
+ }
304
+ $ headers = explode ("\r\n" , $ lastHeaders );
305
+ return $ headers ;
306
+ }
293
307
}
0 commit comments