Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#20222 closed defect (bug) (fixed)

No way to force local HTTP requests through proxy

Reported by: johnbillion's profile johnbillion Owned by: dd32's profile dd32
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: HTTP API Keywords: has-patch
Focuses: Cc:

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 13 years ago.
20222-2.patch (644 bytes) - added by kurtpayne 13 years ago.
Alternate patch
20222.diff (506 bytes) - added by dd32 13 years ago.

Download all attachments as: .zip

Change History (13)

@johnbillion
13 years ago

#1 @johnbillion
13 years ago

  • 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 );

#2 @johnbillion
13 years ago

  • Keywords commit removed

Sorry, didn't mean to add commit tag.

#3 @dd32
13 years ago

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

#4 @johnbillion
13 years ago

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.

#5 @markjaquith
13 years ago

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.

@kurtpayne
13 years ago

Alternate patch

#6 @kurtpayne
13 years ago

  • 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.

#7 follow-up: @dd32
13 years 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)

@dd32
13 years ago

#8 in reply to: ↑ 7 @kurtpayne
13 years 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.

#9 @dd32
13 years ago

  • 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()

#10 @dd32
13 years ago

  • 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.