From 286055935a25448d16e47fee5f459e9e71b775f2 Mon Sep 17 00:00:00 2001 From: Mark Stahl Date: Thu, 6 Sep 2018 04:38:44 -0400 Subject: [PATCH] Fixes #509. Checks for encrypted or forwarded connection before redirecting (#510) --- lib/http-server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/http-server.js b/lib/http-server.js index ebe505c6..51e83f6a 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -90,9 +90,14 @@ function createDevServer (connectionHandler) { var location = 'https://' + host + req.url var agent = req.headers['user-agent'] + // We don't want to force an HTTPS connection if we are already + // encrypted or we are being forwarded through a proxy that may be + // taking care of it. + var encrypted = req.headers['x-forwarded-proto'] || req.connection.encrypted + // We want to force HTTPS connections, but using curl(1) or wget(1) from // the command line can be convenient to quickly check output. - if (/^(curl|wget)/i.test(agent)) { + if (/^(curl|wget)/i.test(agent) || encrypted) { return connectionHandler(req, res) } else { res.writeHead(301, { location: location })