var defaults = {
  trustProtoHeader: false,
  trustAzureHeader: false,
  trustXForwardedHostHeader: false,
  port: 443
}

function applyOptions (options) {
  var settings = {}
  options = options || {}

  for (var option in defaults) {
    settings[option] = options[option] || defaults[option]
  }
  return settings
}

export default function (options) {
  options = applyOptions(options)

  return (req, res, next) => {
    console.log(req.originalUrl)
    let isSecure = req.secure

    if (!isSecure && options.trustProtoHeader) {
      isSecure = ((req.headers['x-forwarded-proto'] || '').substring(0, 5) === 'https')
    }

    if (!isSecure && options.trustAzureHeader && req.headers['x-arr-ssl']) {
      isSecure = true
    }

    if (isSecure) {
      next()
    } else {
      if (req.method === 'GET' || req.method === 'HEAD') {
        var host = options.trustXForwardedHostHeader ? (req.headers['x-forwarded-host'] || req.headers.host) : req.headers.host

        if (options.port === 443) {
          res.redirect(301, 'https://' + host + req.originalUrl)
        } else {
          res.redirect(301, 'https://' + host + ':' + options.port + req.originalUrl)
        }
      } else {
        res.status(403).send('Please use HTTPS when submitting data to this server.')
      }
    }
  }
}

@@ -361,28 +361,16 @@
 tions = 
-applyOptions
 (options
@@ -407,41 +407,8 @@
 %3E %7B%0A
-    console.log(req.originalUrl)%0A
     
@@ -1081,16 +1081,40 @@
 ' + host
+.replace(/:%5B0-9%5D*/g, '')
  + ':' +

Replace port iff specified