Skip to content

Commit

Permalink
add proxy read from env option
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMoelans committed Jan 10, 2025
1 parent 5a42813 commit 9565c21
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
11 changes: 11 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,17 @@ SENTRY_API void sentry_options_set_http_proxy_n(
SENTRY_API const char *sentry_options_get_http_proxy(
const sentry_options_t *opts);

/**
* Sets whether to read the proxy settings from the environment.
*/
SENTRY_API void sentry_options_set_read_proxy_from_environment(
sentry_options_t *opts, int val);
/**
* Returns whether to read the proxy settings from the environment.
*/
SENTRY_API int sentry_options_get_read_proxy_from_environment(
const sentry_options_t *opts);

/**
* Configures the path to a file containing ssl certificates for
* verification.
Expand Down
4 changes: 4 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ sentry_init(sentry_options_t *options)
}
}

if (options->read_proxy_from_environment) {
sentry__set_proxy_from_environment(options);
}

uint64_t last_crash = 0;

// and then we will start the backend, since it requires a valid run
Expand Down
23 changes: 22 additions & 1 deletion src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ sentry_options_new(void)
opts->release = sentry__string_clone(getenv("SENTRY_RELEASE"));
opts->environment = sentry__string_clone(getenv("SENTRY_ENVIRONMENT"));
#endif
sentry_options_set_proxy(opts, getenv("http_proxy"));
if (!opts->environment) {
opts->environment = sentry__string_clone("production");
}
Expand Down Expand Up @@ -277,6 +276,28 @@ sentry_options_get_http_proxy(const sentry_options_t *opts)
return sentry_options_get_proxy(opts);
}

void
sentry_options_set_read_proxy_from_environment(sentry_options_t *opts, int val)
{
opts->read_proxy_from_environment = !!val;
}

int
sentry_options_get_read_proxy_from_environment(const sentry_options_t *opts)
{
return opts->read_proxy_from_environment;
}

void
sentry__set_proxy_from_environment(sentry_options_t *opts)
{
sentry_options_set_proxy(opts, getenv("http_proxy"));
const char *https_proxy = getenv("https_proxy");
if (https_proxy) {
sentry_options_set_proxy(opts, https_proxy);
}
}

void
sentry_options_set_ca_certs(sentry_options_t *opts, const char *path)
{
Expand Down
5 changes: 5 additions & 0 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct sentry_options_s {
bool require_user_consent;
bool symbolize_stacktraces;
bool system_crash_reporter_enabled;
bool read_proxy_from_environment;

sentry_attachment_t *attachments;
sentry_run_t *run;
Expand Down Expand Up @@ -79,4 +80,8 @@ typedef struct sentry_options_s {
*/
sentry_options_t *sentry__options_incref(sentry_options_t *options);

/**
* Sets the proxy value by reading it from the environment.
*/
void sentry__set_proxy_from_environment(sentry_options_t *opts);
#endif

0 comments on commit 9565c21

Please sign in to comment.