#20222 closed defect (bug) (fixed)

No way to force local HTTP requests through proxy

Reported by: johnbillion Owned by: dd32
Priority: normal Milestone: 3.5
Component: HTTP Version:
Severity: normal Keywords: has-patch
Cc: kpayne@…

Description

The HTTP API will send requests through a proxy server if the WP_PROXY_HOST and WP_PROXY_POST constants are defined.

If the host of an HTTP request is the same as the current host (as is the case when a WP-cron request is spawned) then the request won't be sent through the proxy and there is no way to override this (see trunk/wp-includes/class-http.php@20171#L1346).

I use a proxy for logging and debugging HTTP requests and it's not possible for me to send local HTTP requests through the proxy.

Attachments (3)

20222.patch (1.0 KB) - added by johnbillion 14 months ago.
20222-2.patch (644 bytes) - added by kurtpayne 14 months ago.
Alternate patch
20222.diff (506 bytes) - added by dd32 11 months ago.

Download all attachments as: .zip

Change History (13)

  • Keywords commit has-patch added

Patch. The HTTP API can now be told to use the proxy (if one's defined) for local requests by using the following code in your wp-config.php file:

define( 'WP_PROXY_LOCAL_HOSTS', true );
  • Keywords commit removed

Sorry, didn't mean to add commit tag.

I think I'd prefer a filter on the function rather than more constants here

I chose to use another constant just so it was inline with the WP_PROXY_HOST and WP_PROXY_PORT constants. It's the sort of setting which will be done on a per-site basis and it's easier just to drop that constant into wp-config.php rather than using a filter.

Constants box us in. I wish we'd use fewer of them. You can't, for instance, proxy some local requests, but not all, just using a constant.

Alternate patch

  • Cc kpayne@… added

20222-2.patch uses a callback.

You can determine per URL like so:

add_filter( 'proxy_local_urls_callback', function() {
	return 'check_url';
});
function check_url( $url ) {
	return true;  // your logic here
}

Or you can enable all proxying for all local URLs

add_filter( 'proxy_local_urls_callback', '__return_true' );

Default behavior is backwards compatible.

comment:7 follow-up: ↓ 8   dd3211 months ago

@kurtpayne: Is there any reason you've re-invented the wheel so to say here?

Does that approach have any advatages over this patch? (which I'm about to add)

dd3211 months ago

comment:8 in reply to: ↑ 7   kurtpayne11 months ago

Replying to dd32:

@kurtpayne: Is there any reason you've re-invented the wheel so to say here?

No sir. Just lack of practice. :-)

Does that approach have any advatages over this patch? (which I'm about to add)

Nope, your patch looks good. Thanks.

  • Milestone changed from Awaiting Review to 3.5

No sir. Just lack of practice. :-)

Thanks for confirming, I thought that was the case, but was thrown by your use of apply_filters()

  • Owner set to dd32
  • Resolution set to fixed
  • Status changed from new to closed

In [21225]:

WP_HTTP: Add a filter to WP_HTTP_Proxy::send_through_proxy() to allow for plugins to modify which requests are sent to a proxy dynamically. Fixes #20222

Note: See TracTickets for help on using tickets.