/*
HTTP Strict Transport Security (HSTS)

http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec-04

*/

module.exports = function (maxAge, includeSubdomains) {
    if (!maxAge) maxAge = '15768000'; // Approximately 6 months
    var header = "maxAge=" + maxAge;

    if (includeSubdomains) header += '; includeSubdomains';
    
    return function (req, res, next)  {
        if (req.connection.encrypted) {
            res.header('Strict-Transport-Security', header);
        }
        next();
    };
};


/*
HTTP Strict Transport Security (HSTS)

http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec-04

*/

module.exports = function (maxAge, includeSubdomains) {
    if (!maxAge) maxAge = '15768000'; // Approximately 6 months
    var header = "maxAge=" + maxAge;

    if (includeSubdomains) header += '; includeSubdomains';
    
    return function (req, res, next)  {
        if (typeof req.secure !== "undefined" ? req.secure : req.connection.encrypted) {
            res.header('Strict-Transport-Security', header);
        }
        next();
    };
};


Use req.secure if it is set
Use req.secure if it is set
