bug #32083 [HttpClient] fixing passing debug info to progress callback (nicolas-grekas)
This PR was merged into the 4.3 branch.
Discussion
----------
[HttpClient] fixing passing debug info to progress callback
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
NativeHttpClient already has it.
Commits
-------
dc55cf826a
[HttpClient] fixing passing debug info to progress callback
This commit is contained in:
commit
b56591c92d
@ -55,6 +55,7 @@ final class CurlResponse implements ResponseInterface
|
||||
$this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
|
||||
$info = &$this->info;
|
||||
$headers = &$this->headers;
|
||||
$debugBuffer = $this->debugBuffer;
|
||||
|
||||
if (!$info['response_headers']) {
|
||||
// Used to keep track of what we're waiting for
|
||||
@ -88,9 +89,11 @@ final class CurlResponse implements ResponseInterface
|
||||
if ($onProgress = $options['on_progress']) {
|
||||
$url = isset($info['url']) ? ['url' => $info['url']] : [];
|
||||
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
||||
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, static function ($ch, $dlSize, $dlNow) use ($onProgress, &$info, $url, $multi) {
|
||||
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, static function ($ch, $dlSize, $dlNow) use ($onProgress, &$info, $url, $multi, $debugBuffer) {
|
||||
try {
|
||||
$onProgress($dlNow, $dlSize, $url + curl_getinfo($ch) + $info);
|
||||
rewind($debugBuffer);
|
||||
$debug = ['debug' => stream_get_contents($debugBuffer)];
|
||||
$onProgress($dlNow, $dlSize, $url + curl_getinfo($ch) + $info + $debug);
|
||||
} catch (\Throwable $e) {
|
||||
$multi->handlesActivity[(int) $ch][] = null;
|
||||
$multi->handlesActivity[(int) $ch][] = $e;
|
||||
@ -148,12 +151,6 @@ final class CurlResponse implements ResponseInterface
|
||||
if (!$info = $this->finalInfo) {
|
||||
self::perform($this->multi);
|
||||
|
||||
if ('debug' === $type) {
|
||||
rewind($this->debugBuffer);
|
||||
|
||||
return stream_get_contents($this->debugBuffer);
|
||||
}
|
||||
|
||||
$info = array_merge($this->info, curl_getinfo($this->handle));
|
||||
$info['url'] = $this->info['url'] ?? $info['url'];
|
||||
$info['redirect_url'] = $this->info['redirect_url'] ?? null;
|
||||
@ -164,9 +161,10 @@ final class CurlResponse implements ResponseInterface
|
||||
$info['starttransfer_time'] = 0.0;
|
||||
}
|
||||
|
||||
if (!\in_array(curl_getinfo($this->handle, CURLINFO_PRIVATE), ['headers', 'content'], true)) {
|
||||
rewind($this->debugBuffer);
|
||||
$info['debug'] = stream_get_contents($this->debugBuffer);
|
||||
|
||||
if (!\in_array(curl_getinfo($this->handle, CURLINFO_PRIVATE), ['headers', 'content'], true)) {
|
||||
curl_setopt($this->handle, CURLOPT_VERBOSE, false);
|
||||
rewind($this->debugBuffer);
|
||||
ftruncate($this->debugBuffer, 0);
|
||||
|
@ -78,18 +78,12 @@ final class NativeResponse implements ResponseInterface
|
||||
if (!$info = $this->finalInfo) {
|
||||
self::perform($this->multi);
|
||||
|
||||
if ('debug' === $type) {
|
||||
return $this->info['debug'];
|
||||
}
|
||||
|
||||
$info = $this->info;
|
||||
$info['url'] = implode('', $info['url']);
|
||||
unset($info['fopen_time'], $info['size_body'], $info['request_header']);
|
||||
|
||||
if (null === $this->buffer) {
|
||||
$this->finalInfo = $info;
|
||||
} else {
|
||||
unset($info['debug']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user