Opened 14 months ago
Closed 11 months ago
#20222 closed defect (bug) (fixed)
No way to force local HTTP requests through proxy
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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)
Change History (13)
johnbillion — 14 months ago
comment:1
johnbillion — 14 months ago
- Keywords commit has-patch added
I think I'd prefer a filter on the function rather than more constants here
comment:4
johnbillion — 14 months 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.
comment:5
markjaquith — 14 months 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.
- 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.
@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)
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()
comment:10
dd32 — 11 months ago
- Owner set to dd32
- Resolution set to fixed
- Status changed from new to closed
In [21225]:

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: