@httpland/corp-middleware
v1.0.0
Published
HTTP cross-origin resource policy(CORP) middleware
Downloads
20
Maintainers
Readme
corp-middleware
HTTP cross-origin resource policy(CORP) middleware.
Compliant with
Fetch, 3.6. Cross-Origin-Resource-Policy
header.
Middleware
For a definition of Universal HTTP middleware, see the http-middleware project.
Usage
Middleware adds the Cross-Origin-Resource-Policy
header to the response.
import {
corp,
type Handler,
} from "https://deno.land/x/corp_middleware@$VERSION/mod.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";
declare const request: Request;
declare const handler: Handler;
const middleware = corp();
const response = await middleware(request, handler);
assert(response.headers.has("cross-origin-resource-policy"));
yield:
Cross-Origin-Resource-Policy: same-origin
The default field value is same-origin
.
Policy
To change the corp policy, do the following:
import {
corp,
} from "https://deno.land/x/corp_middleware@$VERSION/middleware.ts";
const middleware = corp("cross-origin");
yield:
Cross-Origin-Resource-Policy: cross-origin
Conditions
Middleware will execute if all of the following conditions are met:
- Response does not include
Cross-Origin-Resource-Policy
header
Effects
Middleware may make changes to the following elements of the HTTP message.
- HTTP Headers
- Cross-Origin-Resource-Policy
API
All APIs can be found in the deno doc.
License
Copyright © 2023-present httpland.
Released under the MIT license