From: Tim Düsterhus Date: Thu, 11 Feb 2021 14:30:04 +0000 (+0100) Subject: Use Guzzle's RequestOptions constants X-Git-Tag: 5.4.0_Alpha_1~286 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d4d98a6d7ff15ba7c27400ce555e18a4f811dac4;p=GitHub%2FWoltLab%2FWCF.git Use Guzzle's RequestOptions constants These allow one to easily view the option's description within the IDE. --- diff --git a/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php b/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php index 19764d66c9..7bee94bdd4 100644 --- a/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php +++ b/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php @@ -4,6 +4,7 @@ namespace wcf\action; use GuzzleHttp\ClientInterface; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\RequestOptions; use ParagonIE\ConstantTime\Hex; use Psr\Http\Client\ClientExceptionInterface; use wcf\system\exception\NamedUserException; @@ -52,7 +53,7 @@ abstract class AbstractOauth2Action extends AbstractAction { if (!$this->httpClient) { $this->httpClient = HttpFactory::makeClient([ - 'timeout' => 5, + RequestOptions::TIMEOUT => 5, ]); } diff --git a/wcfsetup/install/files/lib/action/ImageProxyAction.class.php b/wcfsetup/install/files/lib/action/ImageProxyAction.class.php index c5b945a5e8..d672723422 100644 --- a/wcfsetup/install/files/lib/action/ImageProxyAction.class.php +++ b/wcfsetup/install/files/lib/action/ImageProxyAction.class.php @@ -4,6 +4,7 @@ namespace wcf\action; use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\RequestOptions; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\SystemException; use wcf\system\io\File; @@ -105,7 +106,7 @@ class ImageProxyAction extends AbstractAction // download image try { $client = HttpFactory::makeClient([ - 'timeout' => 10, + RequestOptions::TIMEOUT => 10, ]); $request = new Request('GET', $url, [ 'via' => '1.1 wsc', diff --git a/wcfsetup/install/files/lib/system/background/job/DownloadRankImageJob.class.php b/wcfsetup/install/files/lib/system/background/job/DownloadRankImageJob.class.php index 31cba42af6..485957403a 100644 --- a/wcfsetup/install/files/lib/system/background/job/DownloadRankImageJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/DownloadRankImageJob.class.php @@ -3,6 +3,7 @@ namespace wcf\system\background\job; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\RequestOptions; use wcf\data\user\rank\UserRank; use wcf\data\user\rank\UserRankEditor; use wcf\system\io\HttpFactory; @@ -64,7 +65,7 @@ class DownloadRankImageJob extends AbstractBackgroundJob $extension = \pathinfo(Url::parse($rank->rankImage)['path'], \PATHINFO_EXTENSION); if (\in_array($extension, ['gif', 'png', 'jpg', 'jpeg', 'svg', 'webp'])) { $http = HttpFactory::makeClient([ - 'timeout' => 10, + RequestOptions::TIMEOUT => 10, ]); $imageDest = WCF_DIR . UserRank::RANK_IMAGE_DIR . $rank->rankID . '-rankImage.' . $extension; diff --git a/wcfsetup/install/files/lib/system/io/HttpFactory.class.php b/wcfsetup/install/files/lib/system/io/HttpFactory.class.php index bb481058a2..205c50e8f7 100644 --- a/wcfsetup/install/files/lib/system/io/HttpFactory.class.php +++ b/wcfsetup/install/files/lib/system/io/HttpFactory.class.php @@ -4,6 +4,7 @@ namespace wcf\system\io; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; +use GuzzleHttp\RequestOptions; /** * Factory for HTTP Clients. @@ -61,9 +62,9 @@ final class HttpFactory public static function makeClient(array $options = []) { $defaults = [ - 'proxy' => PROXY_SERVER_HTTP, - 'headers' => [], - 'timeout' => 60, + RequestOptions::PROXY => PROXY_SERVER_HTTP, + RequestOptions::HEADERS => [], + RequestOptions::TIMEOUT => 60, ]; foreach ($defaults as $key => $value) { @@ -73,14 +74,14 @@ final class HttpFactory } $foundUserAgent = false; - foreach ($options['headers'] as $headerName => $value) { + foreach ($options[RequestOptions::HEADERS] as $headerName => $value) { if (\strtolower($headerName) === 'user-agent') { $foundUserAgent = true; break; } } if (!$foundUserAgent) { - $options['headers']['user-agent'] = self::getDefaultUserAgent(); + $options[RequestOptions::HEADERS]['user-agent'] = self::getDefaultUserAgent(); } return new Client($options); diff --git a/wcfsetup/install/files/lib/system/style/FontManager.class.php b/wcfsetup/install/files/lib/system/style/FontManager.class.php index 307032e47a..d573067b02 100644 --- a/wcfsetup/install/files/lib/system/style/FontManager.class.php +++ b/wcfsetup/install/files/lib/system/style/FontManager.class.php @@ -6,6 +6,7 @@ use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\RequestOptions; use wcf\system\io\AtomicWriter; use wcf\system\io\HttpFactory; use wcf\system\SingletonFactory; @@ -36,7 +37,7 @@ class FontManager extends SingletonFactory { $this->http = HttpFactory::makeClient([ 'base_uri' => 'https://fonts.woltlab.com/', - 'timeout' => 10, + RequestOptions::TIMEOUT => 10, ]); } diff --git a/wcfsetup/install/files/lib/util/HTTPRequest.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php index 3a5cf27467..c34e21f873 100644 --- a/wcfsetup/install/files/lib/util/HTTPRequest.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -6,6 +6,7 @@ use GuzzleHttp\Exception\BadResponseException; use GuzzleHttp\Exception\TooManyRedirectsException; use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\RequestOptions; use ParagonIE\ConstantTime\Hex; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -188,20 +189,20 @@ final class HTTPRequest $options = [ // No overall timeout - 'timeout' => 0, - 'connect_timeout' => $this->options['timeout'], - 'read_timeout' => $this->options['timeout'], - 'allow_redirects' => [ + RequestOptions::TIMEOUT => 0, + RequestOptions::CONNECT_TIMEOUT => $this->options['timeout'], + RequestOptions::READ_TIMEOUT => $this->options['timeout'], + RequestOptions::ALLOW_REDIRECTS => [ 'max' => $this->options['maxDepth'], 'track_redirects' => true, 'on_redirect' => $redirectHandler, ], ]; if (isset($this->options['maxLength'])) { - $options['stream'] = true; + $options[RequestOptions::STREAM] = true; } if (isset($this->options['auth'])) { - $options['auth'] = [ + $options[RequestOptions::AUTH] = [ $this->options['auth']['username'], $this->options['auth']['password'], ];