I have the following curl code:
$url = "https://example.com/api/blah/";
$result = remoteRequest ($url, 'POST', $postValues, true, true, array("X-Forwarded-For: $_SERVER[REMOTE_ADDR]"));
with the main function being:
function remoteRequest ($url, $type='POST', $postValues=array(), $json=true, $parseResponse=true, $extraHeaders=array())
{
$curl = curl_init ($url);
$postValuesString = '';
if ($json && $postValues) {
$postValuesString = json_encode ($postValues);
}
curl_setopt ($curl, CURLOPT_TIMEOUT, 3);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
if ($extraHeaders) {
curl_setopt ($curl, CURLOPT_HTTPHEADER, $extraHeaders);
}
if ($type == 'POST') {
curl_setopt ($curl, CURLOPT_POST, 1);
}
if ($postValues || $postValuesString) {
curl_setopt ($curl, CURLOPT_POSTFIELDS, $postValuesString ? $postValuesString : $postValues);
}
if ($json) {
if ($type == 'POST') {
curl_setopt ($curl, CURLOPT_CUSTOMREQUEST, "POST");
}
curl_setopt ($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Content-Length: ' . strlen($postValuesString)));
}
$rc = curl_exec ($curl);
curl_close ($curl);
return $rc;
}
I've tried everything I can think of, but the extra headers (x-forwarded-for) are simply not included in the request header.
I've verified this through some debug code as well as routing the curl request through squid and taking a look at it's log file.
Does anybody know what I'm doing wrong and what I have to do in order to get the x-forwarded-for header added to my request? I've even started wondering whether this could be related to me accessing a https (rather than http) URL but I'm guessing it's probably something else.
For the record, I'm using 5.6.9-1+deb.sury.org~trusty+2 on Ubunty 14.04.