3 * Force clients to use an SSL port by redirecting them
6 var kiwi
= require('../kiwi.js');
9 exports
.onhttp = function (ev
, opts
) {
10 var host
, port
= null, i
;
13 host
= ev
.request
.headers
.host
;
15 // Remove the port if one is set
16 if (host
.search(/:/) > -1) {
17 host
= host
.substring(0, host
.search(/:/));
20 for (i
in kiwi
.config
.servers
) {
21 if (kiwi
.config
.servers
[i
].secure
) {
22 port
= kiwi
.config
.servers
[i
].port
;
27 // If we didn't find an SSL listener, don't redirect
32 // No need to specify port 443 since it's the standard
34 host
+= ':' + port
.toString();
37 ev
.response
.writeHead(302, {'Location': 'https://' + host
+ ev
.request
.url
});