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

Honor http_proxy environment variables #1111

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

JoshuaMoelans
Copy link
Member

@JoshuaMoelans JoshuaMoelans commented Jan 9, 2025

Fixes #787

  • add option
  • add tests
  • document what types of proxy strings work and which don't
  • add to docs as to which variables we read (and what order they are read)

Adds option to read http_proxy from environment (also checks https_proxy and prioritizes this if it exists). If this flag is set to true, it will overwrite any previously set proxies with sentry_options_set_proxy.

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 5.88235% with 16 lines in your changes missing coverage. Please review.

Project coverage is 82.53%. Comparing base (092de88) to head (86b1f6c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1111      +/-   ##
==========================================
- Coverage   82.67%   82.53%   -0.14%     
==========================================
  Files          53       53              
  Lines        7930     7947      +17     
  Branches     1240     1242       +2     
==========================================
+ Hits         6556     6559       +3     
- Misses       1263     1277      +14     
  Partials      111      111              

Comment on lines +141 to +143
if (options->read_proxy_from_environment) {
sentry__set_proxy_from_environment(options);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this new option, I'm not sure we still need to support no_proxy; if users want to use the environment variable value in their own code, they can just not set this flag to true (which is the default anyway).

Copy link
Collaborator

@supervacuus supervacuus Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. You always have to consider that this is a feature that the users of our users require from them.

So, for instance, if your application ignores the http_proxy env-vars, your users don't care about the topic and accept that they have to manually configure the proxy config for that application (or even have no proxy config at all).

At some point, you might provide a UI to your users that does something like the following:

(   ) direct HTTP connection.
(   ) manually specify HTTP proxy: _________ .
( * ) read proxy from the environment.

You can route this directly to our proposed options interface. However, once your users have configured the app to read from the environment, they will want to stay with it because it allows them to have a centrally managed proxy configuration rather than defining it separately in every application.

This is where no_proxy enters the picture. So, yes, resetting the proxy config of that app solves the problem, but then the users of our users are essentially back to square 1. Again, this is not a requirement for an initial implementation of that feature but a likely follow-up.

@JoshuaMoelans JoshuaMoelans marked this pull request as ready for review January 14, 2025 12:04
void
sentry__set_proxy_from_environment(sentry_options_t *opts)
{
const char *https_proxy = getenv("https_proxy");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we support upper-case HTTP_PROXY and HTTPS_PROXY too? What happens if HTTP_PROXY and http_proxy are defined?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with only accepting the lower-case versions, but since this is a "thing", we should clearly document the behavior.

Comment on lines 105 to 107
// ensure the proxy starts with `http://`, otherwise ignore it
if (opts->proxy && strstr(opts->proxy, "http://") == opts->proxy) {
const char *ptr = opts->proxy + 7;
Copy link
Member Author

@JoshuaMoelans JoshuaMoelans Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently our Windows transport doesn't take https:// proxies. This should be documented, since we now also read the HTTPS_PROXY environment variable, which on this platform would get ignored.

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

Successfully merging this pull request may close these issues.

Honor http_proxy environment variables
2 participants