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

Added proxy options for PSR-7 Service #16539

Merged
merged 2 commits into from
May 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion core/src/Revolution/modX.php
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,8 @@ protected function _initHttpClient()
// Http Client is created as a factory, so that repeat calls get a fresh client. This is done to make sure
// mutable clients (perhaps they allow setting options after instantiation) do not cause side-effects elsewhere
$this->services->add(ClientInterface::class, $this->services->factory(function() {
return new Client();
$opts = $this->buildHttpClientOptions();
return new Client($opts);
}));
}
if (!$this->services->has(ServerRequestFactoryInterface::class)) {
Expand All @@ -2720,6 +2721,30 @@ protected function _initHttpClient()
}
}

/**
* Build options for the HTTP client based on configuration settings.
*
* @return array The HTTP client options.
*/
private function buildHttpClientOptions() {
$opts = [];
$proxyHost = $this->getOption('proxy_host', null, '');
if (!empty($proxyHost)) {
$proxy_str = $proxyHost;
$proxyPort = $this->getOption('proxy_port', null, '');
if (!empty($proxyPort)) {
$proxy_str .= ':' . $proxyPort;
}
$proxyUsername = $this->getOption('proxy_username', null, '');
if (!empty($proxyUsername)) {
$proxyPassword = $this->getOption('proxy_password', null, '');
$proxy_str = $proxyUsername . ':' . $proxyPassword . '@' . $proxy_str;
}
$opts['proxy'] = $proxy_str;
}
return $opts;
}

/**
* Populates the map of events and registered plugins for each.
*
Expand Down