tiny-etag
TypeScript icon, indicating that this package has built-in type declarations

3.0.3 • Public • Published

tiny-etag

ETag middleware

Example

import {http} from "node:http";
import {woodland} from "woodland";
import {etag} from "tiny-etag";
const max = 1000;
const seed = Math.floor(Math.random() * max) + 1;
const router = woodland({cacheSize: max, defaultHeaders: {"Cache-Control": "no-cache"}, seed: seed});
const etags = etag({cacheSize: max, seed: seed});

router.use(etags.middleware).ignore(etags.middleware);

router.use("/", (req, res) => {
	const body = "Hello World!";

	res.writeHead(200, {"Content-Type": "text/plain", "ETag": etags.create(body)});
	res.end(body);
});

http.createServer(router.route).listen(8000);

API

etag ({cacheSize: 1000, cacheTTL: 0, seed: random, mimetype: "text/plain"})

Returns an tiny-etag instance. Cache TTL concerns do not spread with a notification.

create (arg)

Creates a strong ETag value from arg

hash (arg[, mimetype="text/plain"])

Creates a hash of arg, uses create()

middleware (req, res, next)

Middleware to be used by an http framework

register (url, state)

Adds url to the cache

unregister (url)

Removes url from the cache

License

Copyright (c) 2023 Jason Mulligan Licensed under the BSD-3 license

Install

npm i tiny-etag

DownloadsWeekly Downloads

17

Version

3.0.3

License

BSD-3-Clause

Unpacked Size

19.1 kB

Total Files

8

Last publish

Collaborators

  • avoidwork