Skip to content

Commit 365d167

Browse files
author
Kyra Farrow
committed
[HttpClient] fixing passing debug info to progress callback
1 parent 7c05803 commit 365d167

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

Response/CurlResponse.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
5555
$this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
5656
$info = &$this->info;
5757
$headers = &$this->headers;
58+
$debugBuffer = $this->debugBuffer;
5859

5960
if (!$info['response_headers']) {
6061
// Used to keep track of what we're waiting for
@@ -88,9 +89,11 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
8889
if ($onProgress = $options['on_progress']) {
8990
$url = isset($info['url']) ? ['url' => $info['url']] : [];
9091
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
91-
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, static function ($ch, $dlSize, $dlNow) use ($onProgress, &$info, $url, $multi) {
92+
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, static function ($ch, $dlSize, $dlNow) use ($onProgress, &$info, $url, $multi, $debugBuffer) {
9293
try {
93-
$onProgress($dlNow, $dlSize, $url + curl_getinfo($ch) + $info);
94+
rewind($debugBuffer);
95+
$debug = ['debug' => stream_get_contents($debugBuffer)];
96+
$onProgress($dlNow, $dlSize, $url + curl_getinfo($ch) + $info + $debug);
9497
} catch (\Throwable $e) {
9598
$multi->handlesActivity[(int) $ch][] = null;
9699
$multi->handlesActivity[(int) $ch][] = $e;
@@ -148,12 +151,6 @@ public function getInfo(string $type = null)
148151
if (!$info = $this->finalInfo) {
149152
self::perform($this->multi);
150153

151-
if ('debug' === $type) {
152-
rewind($this->debugBuffer);
153-
154-
return stream_get_contents($this->debugBuffer);
155-
}
156-
157154
$info = array_merge($this->info, curl_getinfo($this->handle));
158155
$info['url'] = $this->info['url'] ?? $info['url'];
159156
$info['redirect_url'] = $this->info['redirect_url'] ?? null;
@@ -164,9 +161,10 @@ public function getInfo(string $type = null)
164161
$info['starttransfer_time'] = 0.0;
165162
}
166163

164+
rewind($this->debugBuffer);
165+
$info['debug'] = stream_get_contents($this->debugBuffer);
166+
167167
if (!\in_array(curl_getinfo($this->handle, CURLINFO_PRIVATE), ['headers', 'content'], true)) {
168-
rewind($this->debugBuffer);
169-
$info['debug'] = stream_get_contents($this->debugBuffer);
170168
curl_setopt($this->handle, CURLOPT_VERBOSE, false);
171169
rewind($this->debugBuffer);
172170
ftruncate($this->debugBuffer, 0);

Response/NativeResponse.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,12 @@ public function getInfo(string $type = null)
7878
if (!$info = $this->finalInfo) {
7979
self::perform($this->multi);
8080

81-
if ('debug' === $type) {
82-
return $this->info['debug'];
83-
}
84-
8581
$info = $this->info;
8682
$info['url'] = implode('', $info['url']);
8783
unset($info['fopen_time'], $info['size_body'], $info['request_header']);
8884

8985
if (null === $this->buffer) {
9086
$this->finalInfo = $info;
91-
} else {
92-
unset($info['debug']);
9387
}
9488
}
9589

0 commit comments

Comments
 (0)