@@ -45,7 +45,6 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
4545 $ this ->multi = $ multi ;
4646
4747 if (\is_resource ($ ch ) || $ ch instanceof \CurlHandle) {
48- unset($ multi ->handlesActivity [(int ) $ ch ]);
4948 $ this ->handle = $ ch ;
5049 $ this ->debugBuffer = fopen ('php://temp ' , 'w+ ' );
5150 if (0x074000 === $ curlVersion ) {
@@ -76,7 +75,17 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
7675 }
7776
7877 curl_setopt ($ ch , CURLOPT_HEADERFUNCTION , static function ($ ch , string $ data ) use (&$ info , &$ headers , $ options , $ multi , $ id , &$ location , $ resolveRedirect , $ logger ): int {
79- return self ::parseHeaderLine ($ ch , $ data , $ info , $ headers , $ options , $ multi , $ id , $ location , $ resolveRedirect , $ logger );
78+ if (0 !== substr_compare ($ data , "\r\n" , -2 )) {
79+ return 0 ;
80+ }
81+
82+ $ len = 0 ;
83+
84+ foreach (explode ("\r\n" , substr ($ data , 0 , -2 )) as $ data ) {
85+ $ len += 2 + self ::parseHeaderLine ($ ch , $ data , $ info , $ headers , $ options , $ multi , $ id , $ location , $ resolveRedirect , $ logger );
86+ }
87+
88+ return $ len ;
8089 });
8190
8291 if (null === $ options ) {
@@ -319,10 +328,10 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
319328 return \strlen ($ data ); // Ignore HTTP trailers
320329 }
321330
322- if ("\r\n" !== $ data ) {
331+ if ('' !== $ data ) {
323332 try {
324333 // Regular header line: add it to the list
325- self ::addResponseHeaders ([substr ( $ data, 0 , - 2 ) ], $ info , $ headers );
334+ self ::addResponseHeaders ([$ data ], $ info , $ headers );
326335 } catch (TransportException $ e ) {
327336 $ multi ->handlesActivity [$ id ][] = null ;
328337 $ multi ->handlesActivity [$ id ][] = $ e ;
@@ -332,7 +341,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
332341
333342 if (0 !== strpos ($ data , 'HTTP/ ' )) {
334343 if (0 === stripos ($ data , 'Location: ' )) {
335- $ location = trim (substr ($ data , 9 , - 2 ));
344+ $ location = trim (substr ($ data , 9 ));
336345 }
337346
338347 return \strlen ($ data );
0 commit comments