I want to detect whether a request is being made over HTTPS or HTTP on Azure Websites

0 votes

I have a Node.js application and I want to be able to detect whether a request is being made over HTTPS or HTTP. So far my redirection looks like this:

// Ensure the page is secure, or that we are running a development build
if (req.headers['x-forwarded-proto'] === 'https' || process.env.NODE_ENV === 'development') {
    res.render('index');
} else {
    winston.info('Request for login page made over HTTP, redirecting to HTTPS');
    res.redirect('https://' + req.host);
}

Which works fine on Nodejitsu, but a redirected HTTPS request doesn't have the 'x-forwarded-proto' header set on Azure. How to detect HTTPS redirection on Azure Websites?

Apr 2, 2019 in Azure by sabby
• 4,370 points
1,105 views

1 answer to this question.

0 votes

It's looking like you can make use of the "x-arr-ssl" header. Azure and Nodejitsu both use proxies to redirect the HTTPS traffic to the HTTP server. So, X-ARR-SSL seems to be the header to check for:

// Ensure the page is secure, or that we are running a development build
if (req.headers['x-forwarded-proto'] === 'https' || req.headers['x-arr-ssl'] || process.env.NODE_ENV === 'development') {
    res.render('index');
} else {
    winston.info('Request for login page made over HTTP, redirecting to HTTPS');
    res.redirect('https://' + req.host);
}
answered Apr 2, 2019 by Prerna
• 1,960 points

Related Questions In Azure

0 votes
1 answer

Is there a way to get ERROR details on Azure website?

You have two options: First, you can turn ...READ MORE

answered May 25, 2018 in Azure by club_seesharp
• 3,450 points
2,632 views
+1 vote
2 answers

How do I establish an connection to Azure IoT Hub? Say a connection like MQTT/AMQP using Python.

Azure IoT Hub comes with 3 SDK's: Service SDK Device ...READ MORE

answered Apr 13, 2018 in Azure by null_void
• 3,220 points
2,207 views
+1 vote
1 answer

Ethereum Error: authentication needed: password or unlock

First, make sure you have an account. web3.personal.listAccounts If ...READ MORE

answered Aug 8, 2018 in Blockchain by Omkar
• 69,220 points
5,257 views
0 votes
1 answer

to create persistent subscription for Azure service bus using node js

My reference is a similar solution at GitHub provided ...READ MORE

answered Apr 9, 2019 in IoT (Internet of Things) by Upasana
• 8,620 points
1,532 views
+1 vote
2 answers
0 votes
1 answer

What OS is Jenkins installed on Azure Virtual Machine?

Under Managed Jenkins there's a section called ...READ MORE

answered Apr 4, 2018 in DevOps & Agile by DareDev
• 6,890 points
854 views
0 votes
1 answer

How to add a body to a HttpWebRequest that is being used with the Azure Service management API?

The following code should help: byte[] buf = ...READ MORE

answered Apr 3, 2019 in Azure by Prerna
• 1,960 points
2,652 views
0 votes
1 answer

Want to upload a blob file with huge size to azure in as little time as possible.

Microsoft Azure Storage Explorer is one of the ...READ MORE

answered Mar 27, 2019 in Azure by Prerna
• 1,960 points
1,355 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP