Refer to public function _get_first_available_transport(). The filter is applied first thing. You can see both the arguments array and the URL are passed in addition to the array of transports.
Your filter callback will want to essentially run a custom version of wp_http_validate_url() that rejects bad URLs as normal unless it is that one URL that is legitimate that is hanging things up in your installation.
For this filter, to accept the URL, simply return the first parameter passed to your callback, the transport array. To reject the URL, return false
. The error message will be ‘There are no HTTP transports available which can complete the requested request.’ Though completely misleading, at least bad URLs are rejected.
In reviewing the WP_Http class again, I noticed there is another possibility. You still cannot alter the unsafe URL check function, but you can override the entire WP_Http::request()
method with the ‘pre_http_request’ filter. You are again passed the arguments and the URL, but now you must do everything the request method does. Not only checking for unsafe URLs, but parse the URL, completely validating it, process headers, verify the encoding, build the actual query and dispatch the request, update cookies, and return the results, among other things.
A lot of stuff, but mostly cut and paste existing code. The main advantage is you can use your custom version of rejecting unsafe URLs and return a proper error if one is found.