bug #34255 [HttpClient] fix after merge from 4.3 (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] fix after merge from 4.3

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

3c6dc96ab4 [HttpClient] fix after merge from 4.3
This commit is contained in:
Nicolas Grekas 2019-11-06 13:03:36 +01:00
commit 62bf1f5002
3 changed files with 12 additions and 9 deletions

View File

@ -170,7 +170,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
}
if (!\is_string($options['auth_ntlm'])) {
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must be string or an array, %s given.', \gettype($options['auth_ntlm'])));
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must be a string or an array, %s given.', \gettype($options['auth_ntlm'])));
}
$curlopts[CURLOPT_USERPWD] = $options['auth_ntlm'];

View File

@ -71,7 +71,7 @@ final class CurlResponse implements ResponseInterface
// Move the pushed response to the activity list
$buffer = $options['buffer'];
if ('headers' !== curl_getinfo($ch, CURLINFO_PRIVATE)) {
if ('H' !== curl_getinfo($ch, CURLINFO_PRIVATE)[0]) {
if ($options['buffer'] instanceof \Closure) {
try {
[$content, $buffer] = [null, $content];
@ -249,17 +249,15 @@ final class CurlResponse implements ResponseInterface
*/
private function close(): void
{
if (self::$performing) {
$this->multi->handlesActivity[$this->id][] = null;
$this->multi->handlesActivity[$this->id][] = new TransportException('Response has been canceled.');
unset($this->multi->openHandles[$this->id], $this->multi->handlesActivity[$this->id]);
curl_setopt($this->handle, CURLOPT_PRIVATE, '_0');
if (self::$performing) {
return;
}
unset($this->multi->openHandles[$this->id], $this->multi->handlesActivity[$this->id]);
curl_multi_remove_handle($this->multi->handle, $this->handle);
curl_setopt_array($this->handle, [
CURLOPT_PRIVATE => '_0',
CURLOPT_NOPROGRESS => true,
CURLOPT_PROGRESSFUNCTION => null,
CURLOPT_HEADERFUNCTION => null,
@ -432,7 +430,12 @@ final class CurlResponse implements ResponseInterface
if (!$content && $options['buffer'] instanceof \Closure && $content = $options['buffer']($headers) ?: null) {
$content = \is_resource($content) ? $content : fopen('php://temp', 'w+');
}
if (null !== $info['error']) {
throw new TransportException($info['error']);
}
} catch (\Throwable $e) {
$multi->handlesActivity[$id] = $multi->handlesActivity[$id] ?? [new FirstChunk()];
$multi->handlesActivity[$id][] = null;
$multi->handlesActivity[$id][] = $e;

View File

@ -181,8 +181,8 @@ final class NativeResponse implements ResponseInterface
$this->content = \is_resource($this->content) ? $this->content : fopen('php://temp', 'w+');
}
if (!$this->buffer) {
throw new TransportException('Response has been canceled.');
if (null !== $this->info['error']) {
throw new TransportException($this->info['error']);
}
} catch (\Throwable $e) {
$this->close();