Skip to content

feat: honor http_proxy environment variables - #1111

Merged
JoshuaMoelans merged 59 commits into
masterfrom
joshua/feat/http_proxy_from_env_variables
Feb 17, 2025
Merged

JoshuaMoelans merged 59 commits into
masterfrom
joshua/feat/http_proxy_from_env_variables

Conversation

@JoshuaMoelans

@JoshuaMoelans JoshuaMoelans commented Jan 9, 2025 •

Copy link
Copy Markdown
Member

Fixes #787

Overview

This started as an additional option to configure, but testing revealed that (some) transports already honor the variable. This PR is now mainly an extensive testing effort to reason about the boundaries & quirks of http_proxy.

One major addition was made to the crashpad handler which now also reads the environment variable if it was set.

TODO

Done

@codecov

codecov Bot commented Jan 9, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 69.23077% with 8 lines in your changes missing coverage. Please review.

Project coverage is 82.56%. Comparing base (d90eec1) to head (93678e0).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1111      +/-   ##
==========================================
- Coverage   82.68%   82.56%   -0.13%     
==========================================
  Files          53       53              
  Lines        7930     7942      +12     
  Branches     1240     1246       +6     
==========================================
  Hits         6557     6557              
- Misses       1263     1270       +7     
- Partials      110      115       +5     

Comment thread src/sentry_core.c Outdated
Comment on lines +141 to +143
if (options->read_proxy_from_environment) {
sentry__set_proxy_from_environment(options);
}

Copy link
Copy Markdown
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).

@supervacuus supervacuus Jan 13, 2025 •

Copy link
Copy Markdown
Collaborator

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
Comment thread src/sentry_options.c Resolved
Comment thread src/sentry_options.c Resolved
Comment thread include/sentry.h Resolved

@supervacuus supervacuus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@JoshuaMoelans

Copy link
Copy Markdown
Member Author

Also, now that we test whether the proxy actually gets used when we prompt it to, this crashpad socks5-proxy test fails on macOS (see runner output). It seems like the proxy isn't used, but when trying this with a non-localhost DSN it seems to work (similar to the remaining Windows failures)).

FAILED tests/test_integration_crashpad.py::test_crashpad_crash_proxy[True-run_args1] - AssertionError

@JoshuaMoelans JoshuaMoelans left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Almost there, just a few remarks left.

Comment thread tests/leaks.txt Resolved
@JoshuaMoelans
JoshuaMoelans merged commit 4ebdbe9 into master Feb 17, 2025
@JoshuaMoelans
JoshuaMoelans deleted the joshua/feat/http_proxy_from_env_variables branch February 17, 2025 11:43
BernhardMarconato pushed a commit to elgatosf/sentry-native that referenced this pull request Apr 21, 2026
* read http_proxy from env. variable

* add proxy read from env option

* update CHANGELOG.md

* Add proxy-from-env command + fix order of init

* reorder https->http proxy fetching

* add proxy_auth tests

* fix CHANGELOG.md

* fix CHANGELOG.md

* fix test to avoid cmake build failed

* add WinHTTP proxy username and password PoC

* remove double set_proxy_credentials call

* fix typos and some mem cleaning

* add docs

* user + test 'sentry__url_parse' for proxy auth

* cleanup

* add first proxy from environment test

* add IPv6 proxy from env test

* proxy-from-env cleanup

* rework integration tests structure

* add tests

* move crashpad test & reusable start_mitmdump

* test cleanup

* fix null-string passing

* clean up os.environ

* add check if request was proxied

* fix uninitialized proxy_url

* add proxy_env finally check/cleanup function

* extract proxy test cleanup/check function

* fix proxy_test_finally + update CHANGELOG.md

* add assert functions

* add all-platform crashpad proxy from env reading

* fix crashpad proxy-from-env test

* read proxy from env winHTTP transport

* add non-localhost hostname set/check/usage

* fix CI to be platform specific

* third time's the charm

* replace the netloc replace with a string replace

* remove accidental proxy host for non-proxy test

* add ignore Curl_getaddrinfo_ex to leaks.txt

* refactor proxy tests

* remove incorrect 'fallback' logic comments + update CONTRIBUTING.md
- wrong bc of localhost-to-localhost proxy ignore in macOS

* add `http_proxy` reading

* update CHANGELOG.md

* read is_secure from dsn

* cleaner proxy reading

* check null dsn

* add tests

* change env clean order

* update crashpad to handle empty linux proxy

* forgot ;

* linux fix with no_proxy +  revert crashpad

* return to <empty> proxy workaround for Linux crashpad transport

* strcmp

* pointer check

* update CONTRIBUTING.md
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