1.0.0-beta.2
HTTP ETag middleware
Attributes
Includes Deno configuration
Repository
Current version released
a year ago
Dependencies
std
etag-middleware
HTTP ETag middleware.
Compliant with RFC 9110, 8.8.3. ETag.
Middleware
For a definition of Universal HTTP middleware, see the http-middleware project.
Usage
From the response, calculate the ETag and add it to the ETag
header.
import { etag } from "https://deno.land/x/etag_middleware@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
const middleware = etag();
const response = await middleware(
new Request("http://localhost"),
(request) => new Response("ok"),
);
assertEquals(response.headers.get("etag"), `"<hex:SHA-1:body>"`);
yield:
ETag: W/"<hex:SHA-1:body>"
The Default ETag is a hexadecimal representation of the sha-1 digest of the Response body.
This is a weak ETag.
Effects
Middleware will effect following:
- HTTP Headers
- ETag
Conditions
Middleware will execute only if the following conditions are met:
- Response body is successful(
2xx
) status code - Response body exists
- Response body is readable
ETag
header does not exist in response
API
All APIs can be found in the deno doc.
License
Copyright © 2023-present httpland.
Released under the MIT license