php-cross-domain-proxy
php-cross-domain-proxy copied to clipboard
Response-Header the right way
The method of splitting the response data by a double \r\n starting at line 175 to get the response-headers and data in one request is by far not ideal.
Since then, there was a bit evolution on this topic, so i want to link you to the proper solution for cUrl to retrieve response headers AND body in a single request and based on it, i changed the code sample below to your variable namings:
$response_headers = [];
// this function is called by curl for each header received
curl_setopt($ch, CURLOPT_HEADERFUNCTION,
function($curl, $header) use (&$response_headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len;
}
);
...
$response_content = curl_exec($ch);