From dccec90acf348072dd8dc1d2829bc610b1cb4542 Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 1 Oct 2011 20:47:33 +0100 Subject: [PATCH] forcessl update --- node/kiwi_modules/forcessl.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/node/kiwi_modules/forcessl.js b/node/kiwi_modules/forcessl.js index 1b4d46d..82e8cf2 100644 --- a/node/kiwi_modules/forcessl.js +++ b/node/kiwi_modules/forcessl.js @@ -7,23 +7,33 @@ var kiwi = require('../kiwi.js'); exports.onhttp = function (ev) { + var host, port = null, i; + // TODO: request.socket.pair seems to only be set in a SSL req, is this // the best way to check for this? if (typeof ev.request.socket.pair === 'undefined') { host = ev.request.headers.host; - //port = 443; - + + // Remove the port if one is set if (host.search(/:/)) { - //port = parseInt(host.substring(host.search(/:/) + 1), 10); host = host.substring(0, host.search(/:/)); } - if (kiwi.config.ports[0].number != 443) { - for (i in kiwi.config.ports) { - if (kiwi.config.ports[i].secure) { - host += ':' + kiwi.config.ports[0].number.toString(); - break; - } - } + + for (i in kiwi.config.ports) { + if (kiwi.config.ports[i].secure) { + port = kiwi.config.ports[0].number; + break; + } + } + + // If we didn't find an SSL listener, don't redirect + if (port == null) { + return ev; + } + + // No need to specify port 443 since it's the standard + if (port !== 443) { + host += ':' + port.toString(); } console.log('https://' + host + ev.request.url); -- 2.25.1