Yurunsoft / Guzzle-Swoole

让基于 Guzzle 的项目完美无缝兼容 Swoole 协程,支持:Guzzle、Elasticsearch client——来自宇润 PHP 全家桶
MIT License
161 stars 21 forks source link

Proxy not working #24

Closed OK93-01-18 closed 3 years ago

OK93-01-18 commented 3 years ago

Hello! I use your Guzzle-Swoole lib in my local project and found issue when try used proxy. Proxy not working. For fix, I updated code in Yurun\Util\Swoole\Guzzle\SwooleHandler 93:

$yurunRequest = $yurunRequest->withAttribute(Attributes::USE_PROXY, true)
    ->withAttribute(Attributes::PROXY_TYPE, $scheme)
    ->withAttribute(Attributes::PROXY_SERVER, $proxyUri->getHost())
    ->withAttribute(Attributes::PROXY_PORT, $proxyUri->getPort())
    ->withAttribute(Attributes::PROXY_USERNAME, $username)
    ->withAttribute(Attributes::PROXY_PASSWORD, $password);

in Yurun\Util\YurunHttp\Handler\Swoole 525 replace switch block:

$userName = $request->getAttribute(Attributes::PROXY_USERNAME, null);
$password = $request->getAttribute(Attributes::PROXY_PASSWORD, null);
switch($type)
{
    case 'http':
        $settings['http_proxy_host'] = $request->getAttribute(Attributes::PROXY_SERVER);
        $settings['http_proxy_port'] = $request->getAttribute(Attributes::PROXY_PORT);
        $userName = $request->getAttribute(Attributes::PROXY_USERNAME, null);
        $password = $request->getAttribute(Attributes::PROXY_PASSWORD, null);
        if (!is_null($userName)) {
            $settings['http_proxy_user'] = $userName;
        }
        if (!is_null($password)) {
            $settings['http_proxy_password'] = $password;
        }
        break;
    case 'socks5':
        $settings['socks5_host'] = $request->getAttribute(Attributes::PROXY_SERVER);
        $settings['socks5_port'] = $request->getAttribute(Attributes::PROXY_PORT);
        if (!is_null($userName)) {
            $settings['socks5_username'] = $userName;
        }
        if (!is_null($password)) {
            $settings['socks5_password'] = $password;
        }
        break;
}

Best Regards, Alex

Yurunsoft commented 3 years ago

Thank you very much for your feedback. This bug has been fixed in the master branch, you can test it to see if it meets the expectation.