# is-https

> Check if the given request is HTTPS

Latest version **4.0.0** (published 2021-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-https
pnpm add is-https
yarn add is-https
bun add is-https
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-05-17 |
| First published | 2017-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Maintainers | pi0 |

## Links

- npm: https://www.npmjs.com/package/is-https
- Repository: https://github.com/unjs/is-https
- Homepage: https://github.com/unjs/is-https#readme
- Issues: https://github.com/unjs/is-https/issues
- npm.io page: https://npm.io/package/is-https

## Recent versions

- 4.0.0 (latest) — 2021-05-17
- 3.0.2 — 2020-12-18
- 3.0.1 — 2020-12-14
- 3.0.0 — 2020-12-14
- 2.0.2 — 2020-06-02
- 2.0.1 — 2020-05-31
- 2.0.0 — 2020-05-31
- 1.0.0 — 2017-07-21

## README

# is-https
> Check if the given request is HTTPS

[![npm](https://img.shields.io/npm/dt/is-https.svg?style=flat-square)](https://npmjs.com/package/is-https)
[![npm (scoped with tag)](https://img.shields.io/npm/v/is-https/latest.svg?style=flat-square)](https://npmjs.com/package/is-https)

## Usage

Install package:

```bash
yarn add is-https
# or
npm install is-https
```

```js
const isHTTPS = require('is-https')
// or
import isHTTPS from 'is-https'
```

```ts
function isHTTPS(req: IncomingMessage, trustProxy: Boolean = true): Boolean | undefined
```

## Behaviour

`isHTTPS` function tries to use 2 different methods for HTTPS detection:

- Test if `x-forwarded-proto` header contains `https`
  - Can be disabled by setting `trustProxy` argument to `false`
- Test if `req.connection.encrypted` is `true`

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](https://www.npmjs.com/package/redirect-ssl) - Connect middleware to enforce HTTPS

## License

MIT

---
_Source: https://npm.io/package/is-https · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
