https://github.com/httpland/referrer-policy-middleware
HTTP referrer policy middleware
https://github.com/httpland/referrer-policy-middleware
fetch-api header http middleware policy referrer referrer-policy security
Last synced: about 1 month ago
JSON representation
HTTP referrer policy middleware
- Host: GitHub
- URL: https://github.com/httpland/referrer-policy-middleware
- Owner: httpland
- License: mit
- Created: 2023-04-02T01:52:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-02T05:30:13.000Z (about 3 years ago)
- Last Synced: 2025-10-12T09:55:18.791Z (9 months ago)
- Topics: fetch-api, header, http, middleware, policy, referrer, referrer-policy, security
- Language: TypeScript
- Homepage: https://deno.land/x/referrer_policy_middleware
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# referrer-policy-middleware
[](https://deno.land/x/referrer_policy_middleware)
[](https://doc.deno.land/https/deno.land/x/referrer_policy_middleware/mod.ts)
[](https://github.com/httpland/referrer-policy-middleware/releases)
[](https://codecov.io/gh/httpland/referrer-policy-middleware)
[](https://github.com/httpland/referrer-policy-middleware/blob/main/LICENSE)
[](https://github.com/httpland/referrer-policy-middleware/actions/workflows/test.yaml)
[](https://nodei.co/npm/@httpland/referrer-policy-middleware/)
HTTP referrer policy middleware.
Compliant with [Referrer Policy](https://www.w3.org/TR/referrer-policy/).
## Middleware
For a definition of Universal HTTP middleware, see the
[http-middleware](https://github.com/httpland/http-middleware) project.
## Usage
Middleware adds the `Referrer-Policy` header to the response.
```ts
import {
type Handler,
referrerPolicy,
} from "https://deno.land/x/referrer_policy_middleware@$VERSION/mod.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";
declare const request: Request;
declare const handler: Handler;
const middleware = referrerPolicy();
const response = await middleware(request, handler);
assert(response.headers.has("referrer-policy"));
```
yield:
```http
Referrer-Policy: strict-origin-when-cross-origin
```
The default field value is `strict-origin-when-cross-origin`.
## Policy
To change the referrer policy, do the following:
```ts
import {
referrerPolicy,
} from "https://deno.land/x/referrer_policy_middleware@$VERSION/middleware.ts";
const middleware = referrerPolicy("no-referrer");
```
yield:
```http
Referrer-Policy: no-referrer
```
Multiple directives may be specified.
The UA ignores directives that are unknown to it and uses the last one.
```ts
import {
referrerPolicy,
} from "https://deno.land/x/referrer_policy_middleware@$VERSION/middleware.ts";
const middleware = referrerPolicy(["no-referrer", "unsafe-url"]);
```
yield:
```http
Referrer-Policy: no-referrer, unsafe-url
```
## Conditions
Middleware will execute if all of the following conditions are met:
- Response does not include `Referrer-Policy` header
## Effects
Middleware may make changes to the following elements of the HTTP message.
- HTTP Headers
- Referrer-Policy
## API
All APIs can be found in the
[deno doc](https://doc.deno.land/https/deno.land/x/referrer_policy_middleware/mod.ts).
## License
Copyright © 2023-present [httpland](https://github.com/httpland).
Released under the [MIT](./LICENSE) license