purpleslurple / PurpleSlurple

PurpleSlurple transcodes web pages to make them granularly accessible.
GNU General Public License v2.0
0 stars 0 forks source link

Determine why Azure App protocol is http #150

Open purpleslurple opened 8 months ago

purpleslurple commented 8 months ago

ps.php appears to be served over http (as detected by the code), but is in fact served (later served) over https. How can I make it so I can test over localhost using http, and use https in production?

purpleslurple commented 8 months ago

purpleslurple: When I auto detect the protocol in ps.php, it returns as http. It's hosted on an Azure Web App, but the page is served over https. What's happening here?

GitHub Copilot: If the $_SERVER['HTTPS'] variable is not set to 'on' even though the page is being served over HTTPS, it's possible that the web server is not properly setting the HTTPS environment variable.

In this case, you can try checking the X-Forwarded-Proto header instead. This header is often used by load balancers and reverse proxies to indicate the protocol used between the client and the proxy.

Here's an example of how you could modify the code to check the X-Forwarded-Proto header:

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
    $protocol = "https";
} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $protocol = "https";
} else {
    $protocol = "http";
}

In this modified code, the $_SERVER['HTTP_X_FORWARDED_PROTO'] variable is checked to see if it is set to 'https'. If it is, then the protocol is set to "https". Otherwise, the $_SERVER['HTTPS'] variable is checked as before.

Note that the X-Forwarded-Proto header may not be set by your web server, depending on how it is configured. If this is the case, you may need to check the documentation for your web server or contact your hosting provider for assistance.

purpleslurple commented 8 months ago

See Pull Request #151