@@ -45,7 +45,6 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
45
45
$ this ->multi = $ multi ;
46
46
47
47
if (\is_resource ($ ch ) || $ ch instanceof \CurlHandle) {
48
- unset($ multi ->handlesActivity [(int ) $ ch ]);
49
48
$ this ->handle = $ ch ;
50
49
$ this ->debugBuffer = fopen ('php://temp ' , 'w+ ' );
51
50
if (0x074000 === $ curlVersion ) {
@@ -76,7 +75,17 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
76
75
}
77
76
78
77
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 ;
80
89
});
81
90
82
91
if (null === $ options ) {
@@ -319,10 +328,10 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
319
328
return \strlen ($ data ); // Ignore HTTP trailers
320
329
}
321
330
322
- if ("\r\n" !== $ data ) {
331
+ if ('' !== $ data ) {
323
332
try {
324
333
// Regular header line: add it to the list
325
- self ::addResponseHeaders ([substr ( $ data, 0 , - 2 ) ], $ info , $ headers );
334
+ self ::addResponseHeaders ([$ data ], $ info , $ headers );
326
335
} catch (TransportException $ e ) {
327
336
$ multi ->handlesActivity [$ id ][] = null ;
328
337
$ multi ->handlesActivity [$ id ][] = $ e ;
@@ -332,7 +341,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
332
341
333
342
if (0 !== strpos ($ data , 'HTTP/ ' )) {
334
343
if (0 === stripos ($ data , 'Location: ' )) {
335
- $ location = trim (substr ($ data , 9 , - 2 ));
344
+ $ location = trim (substr ($ data , 9 ));
336
345
}
337
346
338
347
return \strlen ($ data );
0 commit comments