The http_request_version WordPress PHP Filter allows you to modify the version of the HTTP protocol used in a request.
Usage
add_filter('http_request_version', 'my_custom_http_version', 10, 2);
function my_custom_http_version($version, $url) {
// your custom code here
return $version;
}
Parameters
$version(string) – Version of HTTP used. Accepts ‘1.0’ and ‘1.1’. Default ‘1.0’.$url(string) – The request URL.
More information
See WordPress Developer Resources: http_request_version
Examples
Change HTTP version to 1.1 for all requests
Modify the HTTP version used in all requests to HTTP 1.1.
add_filter('http_request_version', 'change_to_http_1_1', 10, 2);
function change_to_http_1_1($version, $url) {
$version = '1.1';
return $version;
}
Change HTTP version to 1.0 for specific domain
Modify the HTTP version to 1.0 for requests to a specific domain.
add_filter('http_request_version', 'change_to_http_1_0_for_domain', 10, 2);
function change_to_http_1_0_for_domain($version, $url) {
if (strpos($url, 'example.com') !== false) {
$version = '1.0';
}
return $version;
}
Use HTTP 1.1 for HTTPS requests
Use HTTP 1.1 for requests made over HTTPS.
add_filter('http_request_version', 'use_http_1_1_for_https', 10, 2);
function use_http_1_1_for_https($version, $url) {
if (strpos($url, 'https://') !== false) {
$version = '1.1';
}
return $version;
}
Change HTTP version based on request method
Change the HTTP version to 1.1 for POST requests.
add_filter('http_request_version', 'use_http_1_1_for_post_requests', 10, 2);
function use_http_1_1_for_post_requests($version, $url) {
global $wp_version;
if ('POST' == $wp_version['method']) {
$version = '1.1';
}
return $version;
}
Use HTTP 1.1 for requests to an API
Modify the HTTP version to 1.1 for requests to a specific API.
add_filter('http_request_version', 'use_http_1_1_for_api_requests', 10, 2);
function use_http_1_1_for_api_requests($version, $url) {
if (strpos($url, 'api.example.com') !== false) {
$version = '1.1';
}
return $version;
}