4.0.0 • Published 4 years ago
is-https v4.0.0
is-https
Check if the given request is HTTPS
Usage
Install package:
yarn add is-https
# or
npm install is-httpsconst isHTTPS = require('is-https')
// or
import isHTTPS from 'is-https'function isHTTPS(req: IncomingMessage, trustProxy: Boolean = true): Boolean | undefinedBehaviour
isHTTPS function tries to use 2 different methods for HTTPS detection:
- Test if
x-forwarded-protoheader containshttps- Can be disabled by setting
trustProxyargument tofalse
- Can be disabled by setting
- Test if
req.connection.encryptedistrue
Returns either true or false based on checks or undefined if no check was reliable.
TIP: If you want to redirect users from http to https, it is better using isHTTPS(req) === false to avoid redirect loops.
Related
- redirect-ssl - Connect middleware to enforce HTTPS
License
MIT