Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provision support for PROXY url. #51

Open
Sachin796 opened this issue Jun 7, 2022 · 4 comments
Open

Provision support for PROXY url. #51

Sachin796 opened this issue Jun 7, 2022 · 4 comments

Comments

@Sachin796
Copy link

Sachin796 commented Jun 7, 2022

I am currently trying to use the gem to connect to the Pagerduty API from a server which only allows proxy url to access the internet. I would like to request a feature where you can make provisions to allow proxy parameter when we create Pagerduty::Connection.new, and when it actually connects using Faraday here . Below is the screenshot of the error that I am getting.

ssl_error

When I create my own connection using Faraday with the proxy key, it works fine, connects to Pagerduty API and does all the operations. But I would like to use the gem for other features but with this support inbuilt.

working_proxy

@Sachin796 Sachin796 changed the title Provision support for PROXY_URL. Provision support for PROXY url. Jun 7, 2022
@technicalpickles
Copy link
Owner

I'm not actively working on this, but would be happy to review code to include a feature like this. I'm curious if there are any conventions that other API libraries follow for conventions. I have not seen any myself, but I haven't really used a proxy before.

If there is a good way to do it within Faraday, @connection has an attr accessor, so one thing you could do is make changes to it for testing.

@Sachin796
Copy link
Author

Thanks for the reply.
As I mentioned the above screenshot works for me.. but it does have its own limitations that I am currently facing issue with. It has some issue's related to Connection Timeout, so I wanted to replace that with what the gem can provide.

There is one more gem that pagerduty recommends from their end for other tasks. I have seen that gem implementing this functionality in the here.

I am not sure how efficiently it is working but pretty sure that it handles the proxy error that I am facing.

@technicalpickles
Copy link
Owner

technicalpickles commented Jun 10, 2022

We are using the faraday gem, so I was googling "faraday proxy", and came across these docs

Faraday will try to automatically infer the proxy settings from your system using URI#find_proxy. This will retrieve them from environment variables such as http_proxy, ftp_proxy, no_proxy, etc. If for any reason you want to disable this behavior, you can do so by setting the global variable ignore_env_proxy:

Faraday.ignore_env_proxy = true

You can also specify a custom proxy when initializing the connection:

conn = Faraday.new('http://www.example.com', proxy: 'http://proxy.com')

URI.find_proxy says:

The proxy URI is obtained from environment variables such as http_proxy, ftp_proxy, no_proxy, etc. If there is no proper proxy, nil is returned.

If the optional parameter env is specified, it is used instead of ENV.

Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.) are examined, too.

But http_proxy and HTTP_PROXY is treated specially under CGI environment. It’s because HTTP_PROXY may be set by Proxy: header. So HTTP_PROXY is not used. http_proxy is not used too if the variable is case insensitive. CGI_HTTP_PROXY can be used instead.

Given that, it seems that setting HTTP_PROXY should work. Can you try that and see if it works? If it doesn't, maybe we need a newer faraday version dependency.

And failing that, it should be straightforward to make it configurable from the constructor and/or a proxy environment variable.

@Sachin796
Copy link
Author

Hi,
Thank you for the suggestions. I understood what you are saying. I have tried the first suggestion in the message above. I have verified that the HTTP_PROXY env variable was already set while I was running my application. The issue that I had mentioned where it gave me SSL connect error, was along with the environment variable HTTP_PROXY already been set. So I think whatever was mentioned in the documentation did not work out.
Can we proceed with the other approach..?.. which included newer faraday version dependency. As per my understanding, I think this should be the changes that are to be made in the gem itself. I want to try that approach and test it out as well. And it that doesn't work out .. we can proceed with the final approach that you mentioned.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants