@@ -113,19 +113,14 @@ public function sendRequest(RequestInterface $request)
113113
114114 $ headerSize = $ info ['header_size ' ];
115115 $ rawHeaders = substr ($ raw , 0 , $ headerSize );
116+ $ headers = $ this ->parseRawHeaders ($ rawHeaders );
116117
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 ) {
125119 $ header = trim ($ header );
126120 if ('' === $ header ) {
127121 continue ;
128122 }
123+
129124 // Status line
130125 if (substr (strtolower ($ header ), 0 , 5 ) === 'http/ ' ) {
131126 $ parts = explode (' ' , $ header , 3 );
@@ -134,6 +129,7 @@ public function sendRequest(RequestInterface $request)
134129 ->withProtocolVersion (substr ($ parts [0 ], 5 ));
135130 continue ;
136131 }
132+
137133 // Extract header
138134 $ parts = explode (': ' , $ header , 2 );
139135 $ headerName = trim (urldecode ($ parts [0 ]));
@@ -290,4 +286,22 @@ private function createHeaders(RequestInterface $request, array $options)
290286 }
291287 return $ curlHeaders ;
292288 }
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+ }
293307}
0 commit comments