From 5b36a9722eb8c693ff9831023cfb807474eab07c Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Mon, 11 Jan 2021 11:15:13 -0800 Subject: [PATCH] updates for Swoole 4.6.1 --- output/swoole/constants.php | 6 ++-- .../swoole_library/src/core/Curl/Handler.php | 33 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/output/swoole/constants.php b/output/swoole/constants.php index ec29fd2a..9048c995 100644 --- a/output/swoole/constants.php +++ b/output/swoole/constants.php @@ -1,10 +1,10 @@ proxy) { - $proxy = explode(':', $this->proxy); - $proxyPort = $proxy[1] ?? $this->proxyPort; - $proxy = $proxy[0]; + $parse = parse_url($this->proxy); + $proxy = $parse['host'] ?? $parse['path']; + $proxyPort = $parse['port'] ?? $this->proxyPort; + $proxyUsername = $parse['user'] ?? $this->proxyUsername; + $proxyPassword = $parse['pass'] ?? $this->proxyPassword; + $proxyType = $parse['scheme'] ?? $this->proxyType; + if (is_string($proxyType)) { + if ($proxyType === 'socks5') { + $proxyType = CURLPROXY_SOCKS5; + } else { + $proxyType = CURLPROXY_HTTP; + } + } + if (!filter_var($proxy, FILTER_VALIDATE_IP)) { $ip = Swoole\Coroutine::gethostbyname($proxy, AF_INET, $this->clientOptions['connect_timeout'] ?? -1); if (!$ip) { @@ -656,25 +667,25 @@ private function execute() } $this->proxy = $proxy = $ip; } - switch ($this->proxyType) { + switch ($proxyType) { case CURLPROXY_HTTP: $proxyOptions = [ 'http_proxy_host' => $proxy, 'http_proxy_port' => $proxyPort, - 'http_proxy_username' => $this->proxyUsername, - 'http_proxy_password' => $this->proxyPassword, + 'http_proxy_username' => $proxyUsername, + 'http_proxy_password' => $proxyPassword, ]; break; case CURLPROXY_SOCKS5: $proxyOptions = [ 'socks5_host' => $proxy, 'socks5_port' => $proxyPort, - 'socks5_username' => $this->proxyUsername, - 'socks5_password' => $this->proxyPassword, + 'socks5_username' => $proxyUsername, + 'socks5_password' => $proxyPassword, ]; break; default: - throw new CurlException("Unexpected proxy type [{$this->proxyType}]"); + throw new CurlException("Unexpected proxy type [{$proxyType}]"); } } /*