Mirror WordPress http proxy configuration for Google Client
Feature Description
Some sites use/require an HTTP proxy to make requests. WordPress provides a number of constants for configuring the WP HTTP API to use a proxy.
The HTTP client used by Google_Client should mirror the same http proxy configuration for WordPress if its constants are defined: WP_PROXY_HOST and WP_PROXY_PORT
Proxy credentials should be supported as well if set: WP_PROXY_USERNAME, WP_PROXY_PASSWORD
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Allow users to rely on
WP_PROXY_*constants to use an HTTP proxy for requests issued byGoogle_Client(now mostlyGoogle_Site_Kit_Client).
Implementation Brief
- Use core's
WP_HTTP_Proxyclass to detect the active state, and retreive values from core constants- There is no global object for this (nor does there need to be), we can instantiate and keep this as a instance property on
OAuth_Clientas$http_proxy
- There is no global object for this (nor does there need to be), we can instantiate and keep this as a instance property on
- In
OAuth_Client::get_client(), check if$http_proxy->is_enabled()- configure the Google client with the proxy configuration$proxy_host = $this->http_proxy->host() . ':' . $this->http_proxy->port(); if ( $this->http_proxy->use_authentication() ) { $proxy_host = $this->http_proxy->authentication() . '@' . $proxy_host; } $client->getHttpClient()->setDefaultOption( 'proxy', $proxy_host ); $ssl_verify = $client->getHttpClient()->getDefaultOption( 'verify' ); $client->getHttpClient()->setDefaultOption( 'verify', apply_filters( 'https_ssl_verify', $ssl_verify, null ) );
QA Brief
This is documented for testing locally as this might be more difficult to test on a live site
- Install an HTTP proxy locally, if you don't have one already
https://docs.mitmproxy.org/stable/overview-installation/- Start the proxy by running
mitmproxynote the port in the bottom right (default:8080)
- Start the proxy by running
- Configure the proxy host and port in your
wp-config.phpdefine( 'WP_PROXY_HOST', 'host.docker.internal' ); define( 'WP_PROXY_PORT', '8080' );For me, this is
host.docker.internalbecause I'm using Docker locally If you're using something else, this may belocalhost, but you want to target your host machine, where the proxy is listening - Install this plugin to disable SSL verification
- Click around Site Kit, you should start to see lines appearing (see below)
- If you see errors, your proxy is not configured properly
- Go to the WordPress Dashboard > Updates page, and click Check Again to force a request from WordPress to check for updates. You should see this in mitmproxy.
- Go to the Site Kit dashboard (setup if necessary).
A few ways to trigger requests:- Set up a new module that makes requests, such as Analytics or Tag Manager
- Switch the date range on a dashboard page
- Clear your browser's Session Storage and reload a Site Kit dashboard page
- You should see requests to
googleapis.comin mitmproxy to confirm that requests are going through it - When done, press
qto stop mitmproxy, andyto confirm from the processes terminal window
Example of requests seen in mitmproxy

Changelog entry
- Allow users to rely on
WP_PROXY_*constants to use an HTTP proxy for requests issued byGoogle_Client.
IB ✅
Let's clarify in a comment, and probably also in naming variables/properties $http_proxy, that this is not related to the "Site Kit proxy".
Tested
Ran through the proxy setup, confirmed proxy is functional

Ran through some tests setting up and removing GA.
Confirmed googleapi requests are coming through:

Passed QA ✅