I checked amazon.com
website for retrive X-Amz-Cf-Id
header which I belive is not a standard header and for me it is working fine:
function wpse_288865_featch_header() {
$response = wp_remote_get('https://www.amazon.com/');
$custom_header = wp_remote_retrieve_header($response, 'X-Amz-Cf-Id');
var_dump($custom_header);
exit;
}
add_action('init', 'wpse_288865_featch_header');
Sometimes amazon.com
is not returning this header so please refresh your WordPress site couple of times.
I also inspected WordPress core for parsing request and didn’t found some kind of whitelist of headers. It is only removing transfer-encoding
and connection
headers.
Please check if you make proper request to your site. For the first time I have checked google.com
and have similar issue. I couldn’t get the headers which I’ve seen that google.com
should return. Problem was that google.com
do not allow me to make such a request and in return I get HTTP/1.1 403 Forbidden
response which obviously return completely different headers that HTTP/1.1 200
response.