[HttpClient] fixing passing debug info to progress callback
This commit is contained in:
parent
5af1e9e1a5
commit
dc55cf826a
@ -55,6 +55,7 @@ final class CurlResponse implements ResponseInterface
|
|||||||
$this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
|
$this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
|
||||||
$info = &$this->info;
|
$info = &$this->info;
|
||||||
$headers = &$this->headers;
|
$headers = &$this->headers;
|
||||||
|
$debugBuffer = $this->debugBuffer;
|
||||||
|
|
||||||
if (!$info['response_headers']) {
|
if (!$info['response_headers']) {
|
||||||
// Used to keep track of what we're waiting for
|
// Used to keep track of what we're waiting for
|
||||||
@ -88,9 +89,11 @@ final class CurlResponse implements ResponseInterface
|
|||||||
if ($onProgress = $options['on_progress']) {
|
if ($onProgress = $options['on_progress']) {
|
||||||
$url = isset($info['url']) ? ['url' => $info['url']] : [];
|
$url = isset($info['url']) ? ['url' => $info['url']] : [];
|
||||||
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
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 {
|
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) {
|
} catch (\Throwable $e) {
|
||||||
$multi->handlesActivity[(int) $ch][] = null;
|
$multi->handlesActivity[(int) $ch][] = null;
|
||||||
$multi->handlesActivity[(int) $ch][] = $e;
|
$multi->handlesActivity[(int) $ch][] = $e;
|
||||||
@ -148,12 +151,6 @@ final class CurlResponse implements ResponseInterface
|
|||||||
if (!$info = $this->finalInfo) {
|
if (!$info = $this->finalInfo) {
|
||||||
self::perform($this->multi);
|
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 = array_merge($this->info, curl_getinfo($this->handle));
|
||||||
$info['url'] = $this->info['url'] ?? $info['url'];
|
$info['url'] = $this->info['url'] ?? $info['url'];
|
||||||
$info['redirect_url'] = $this->info['redirect_url'] ?? null;
|
$info['redirect_url'] = $this->info['redirect_url'] ?? null;
|
||||||
@ -164,9 +161,10 @@ final class CurlResponse implements ResponseInterface
|
|||||||
$info['starttransfer_time'] = 0.0;
|
$info['starttransfer_time'] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\in_array(curl_getinfo($this->handle, CURLINFO_PRIVATE), ['headers', 'content'], true)) {
|
|
||||||
rewind($this->debugBuffer);
|
rewind($this->debugBuffer);
|
||||||
$info['debug'] = stream_get_contents($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);
|
curl_setopt($this->handle, CURLOPT_VERBOSE, false);
|
||||||
rewind($this->debugBuffer);
|
rewind($this->debugBuffer);
|
||||||
ftruncate($this->debugBuffer, 0);
|
ftruncate($this->debugBuffer, 0);
|
||||||
|
@ -78,18 +78,12 @@ final class NativeResponse implements ResponseInterface
|
|||||||
if (!$info = $this->finalInfo) {
|
if (!$info = $this->finalInfo) {
|
||||||
self::perform($this->multi);
|
self::perform($this->multi);
|
||||||
|
|
||||||
if ('debug' === $type) {
|
|
||||||
return $this->info['debug'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$info = $this->info;
|
$info = $this->info;
|
||||||
$info['url'] = implode('', $info['url']);
|
$info['url'] = implode('', $info['url']);
|
||||||
unset($info['fopen_time'], $info['size_body'], $info['request_header']);
|
unset($info['fopen_time'], $info['size_body'], $info['request_header']);
|
||||||
|
|
||||||
if (null === $this->buffer) {
|
if (null === $this->buffer) {
|
||||||
$this->finalInfo = $info;
|
$this->finalInfo = $info;
|
||||||
} else {
|
|
||||||
unset($info['debug']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user