From 480d2fea4d69f3fe354f75fba7115be9fa09cd4a Mon Sep 17 00:00:00 2001 From: Darren Date: Thu, 20 Oct 2011 11:58:48 +0100 Subject: [PATCH] forcessl server module fix --- server/app.js | 10 +++++----- server/kiwi_modules/forcessl.js | 13 +++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/server/app.js b/server/app.js index a36bfdb..df7ce55 100644 --- a/server/app.js +++ b/server/app.js @@ -532,7 +532,7 @@ this.httpHandler = function (request, response) { min = {}, public_http_path, port, ssl, host, obj, args, ircuri, pass, target, modifiers, query, secure = (typeof request.client.encrypted === 'object'); - //try { + try { if (kiwi.config.handle_http) { // Run through any plugins.. args = {request: request, response: response, ssl: secure}; @@ -708,10 +708,10 @@ this.httpHandler = function (request, response) { } } - //} catch (e) { - // console.log('ERROR app.httpHandler()'); - // console.log(e); - //} + } catch (e) { + console.log('ERROR app.httpHandler()'); + console.log(e); + } }; diff --git a/server/kiwi_modules/forcessl.js b/server/kiwi_modules/forcessl.js index b8ae4e5..d510299 100644 --- a/server/kiwi_modules/forcessl.js +++ b/server/kiwi_modules/forcessl.js @@ -9,9 +9,7 @@ var kiwi = require('../kiwi.js'); exports.onhttp = function (ev, opts) { 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 (!opts.ssl) { + if (!ev.ssl) { host = ev.request.headers.host; // Remove the port if one is set @@ -19,9 +17,9 @@ exports.onhttp = function (ev, opts) { host = host.substring(0, host.search(/:/)); } - for (i in kiwi.config.ports) { - if (kiwi.config.ports[i].secure) { - port = kiwi.config.ports[i].number; + for (i in kiwi.config.servers) { + if (kiwi.config.servers[i].secure) { + port = kiwi.config.servers[i].port; break; } } @@ -35,8 +33,7 @@ exports.onhttp = function (ev, opts) { if (port !== 443) { host += ':' + port.toString(); } - - console.log('https://' + host + ev.request.url); + ev.response.writeHead(302, {'Location': 'https://' + host + ev.request.url}); ev.response.end(); -- 2.25.1