softius / php-cross-domain-proxy

PHP Proxy for Cross Domain Requests
GNU General Public License v3.0
269 stars 141 forks source link

Do not respond with 200 OK if proxied request fails #41

Open avbentem opened 3 years ago

avbentem commented 3 years ago

Currently fatal errors such as invalid domains simply return 200 OK. To mitigate that one could, e.g., throw 502 Bad Gateway instead.

Change:

// retrieve response (headers and content)
$response = curl_exec($ch);
curl_close($ch);

...into:

// retrieve response (headers and content)
$response = curl_exec($ch);
if ($response === false) {
    http_response_code(502);
    echo 'Failed to proxy to ' . $request_url . ': ' . curl_error($ch);
    curl_close($ch);
    exit();
}
curl_close($ch);