Skip to content

Allow specify cURL options for connections to providers #25

@gnadelwartz

Description

@gnadelwartz

Hello mremi,

I must use UrlShortner with socks5 for some reasons. Unfortunately the typical shell hackers solution using proxychains shorten ... does not work with php compiled against glibc.

The solution for my own calls to cURL is to provide some cURL options:

                curl_setopt($this->handler, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
                curl_setopt($this->handler, CURLOPT_PROXY, 'localhost');

unfortunately - for me - you are using guzzle so I can't set CURLOPT direct, but luckly guzzle privides the possiblilty to pass cURL options

As UrlShortner is working with user and password on my server, I tried to add the the socks5 options to your bitly provider for shortening, but it has ho effect:

    public function shorten(LinkInterface $link, $domain = null)
    {
        $client = $this->createClient();

        $this->options['headers']['Authorization'] = 'Bearer '.$this->auth->getAccessToken();

        $response = $client->post('/v4/shorten', array_merge([
            'json' => [
                'domain'   => $domain,
                'long_url' => $link->getLongUrl(),
            ],

       'curl' => [
            CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME,
            CURLOPT_PROXY => 'localhost'
        ],

        ], $this->options));

        $response = $this->validate($response);

        $link->setShortUrl($response->link);
    }

Are I'm doing something fundamentally worng or did I miss something?

Any other ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions