core icon indicating copy to clipboard operation
core copied to clipboard

Force using proxy for http client

Open demon-ru opened this issue 9 years ago • 7 comments

It is no secret that in some countries, the telegram is already blocked or will be blocked soon. I suggest to modify the code to pass the proxy options to the constructor of the Client class

For example:

  1. new method Telegram::getHttpClientOptions() { return []; }
  2. and use it in Request::initialize to pass result of method to the GuzzleHttp\Client

thanks.

demon-ru avatar Oct 06 '17 17:10 demon-ru

I believe if you want to proxy your requests you can simply use custom guzzle client:

Request::setClient(new \GuzzleHttp\Client([
        'base_uri' => 'https://api.telegram.org',
        'proxy' => 'tcp://1.2.3.4:125',
    ]));

in hook script before handling the webhook.

jacklul avatar Oct 06 '17 19:10 jacklul

@demon-ru Did @jacklul's suggestion work for you?

noplanman avatar Oct 10 '17 18:10 noplanman

It might help me to use proxy. But will create a headache to track and repeat options for creating Client. It is hoped that there will not appear anything except base_uri.

demon-ru avatar Oct 10 '17 18:10 demon-ru

Could you please explain your scenario a bit more so we can try to understand it better?

You'd like to proxy only certain requests?

noplanman avatar Oct 11 '17 08:10 noplanman

Proxies will be used for all calls (in case of blocking). My task is to add the configuration options of the Client (http client). Not create a Сlient, knowing all the options and configuration rules. But just to add some options.

The proposed option will work. But I need to know and support all the other options and rules creation. Soothes while only that now it is only one option (base_url).

demon-ru avatar Oct 11 '17 08:10 demon-ru

As you say, there are no special options required, just base_url.

So that should work perfectly fine for what you need. If at some point more options are required (which I honestly don't think so any time soon), we can revisit this issue.

Can we close off then for now?

noplanman avatar Oct 11 '17 17:10 noplanman

Yes. Thank you.

demon-ru avatar Oct 12 '17 12:10 demon-ru