diff --git a/lib/middleware/hsts.js b/lib/middleware/hsts.js
index <HASH>..<HASH> 100644
--- a/lib/middleware/hsts.js
+++ b/lib/middleware/hsts.js
@@ -12,7 +12,7 @@ module.exports = function (maxAge, includeSubdomains) {
     if (includeSubdomains) header += '; includeSubdomains';
     
     return function (req, res, next)  {
-        if (req.connection.encrypted) {
+        if (typeof req.secure !== "undefined" ? req.secure : req.connection.encrypted) {
             res.header('Strict-Transport-Security', header);
         }
         next();
Use req.secure if it is set