Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add http timeouts even if no http_proxy is used #1034

Merged
merged 5 commits into from
Jul 3, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/HttpClient/HttpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,36 @@ public function create(Options $options): HttpAsyncClientInterface
throw new \RuntimeException('The "http_proxy" option does not work together with a custom HTTP client.');
}

if (null === $httpClient && null !== $options->getHttpProxy()) {
if (null === $httpClient) {
if (class_exists(GuzzleHttpClient::class)) {
/** @psalm-suppress InvalidPropertyAssignmentValue */
$httpClient = GuzzleHttpClient::createWithConfig([
GuzzleHttpClientOptions::PROXY => $options->getHttpProxy(),
$guzzleConfig = [
/** @psalm-suppress UndefinedClass */
GuzzleHttpClientOptions::TIMEOUT => self::DEFAULT_HTTP_TIMEOUT,
/** @psalm-suppress UndefinedClass */
GuzzleHttpClientOptions::CONNECT_TIMEOUT => self::DEFAULT_HTTP_CONNECT_TIMEOUT,
]);
} elseif (class_exists(CurlHttpClient::class)) {
];

if (null !== $options->getHttpProxy()) {
/** @psalm-suppress UndefinedClass */
$guzzleConfig[GuzzleHttpClientOptions::PROXY] = $options->getHttpProxy();
}

/** @psalm-suppress InvalidPropertyAssignmentValue */
$httpClient = new CurlHttpClient($this->responseFactory, $this->streamFactory, [
CURLOPT_PROXY => $options->getHttpProxy(),
$httpClient = GuzzleHttpClient::createWithConfig($guzzleConfig);
} elseif (class_exists(CurlHttpClient::class)) {
$curlConfig = [
CURLOPT_TIMEOUT => self::DEFAULT_HTTP_TIMEOUT,
CURLOPT_CONNECTTIMEOUT => self::DEFAULT_HTTP_CONNECT_TIMEOUT,
]);
} else {
];

if (null !== $options->getHttpProxy()) {
$curlConfig[CURLOPT_PROXY] = $options->getHttpProxy();
}

/** @psalm-suppress InvalidPropertyAssignmentValue */
$httpClient = new CurlHttpClient($this->responseFactory, $this->streamFactory, $curlConfig);
} elseif (null !== $options->getHttpProxy()) {
throw new \RuntimeException('The "http_proxy" option requires either the "php-http/curl-client" or the "php-http/guzzle6-adapter" package to be installed.');
}
}
Expand Down