概要
シンプルなHTTP ETagを生成
その他のプロジェクト計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- +1
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルetag
Create simple HTTP ETags.
This module generates HTTP ETags for use in HTTP responses. See RFC 9110, Section 8.8.3.
Installation
This is a Node.js module available through the npm registry. Installation is done using the npm install command:
$ npm install etag
API
import { etag } from "etag";
etag(entity, [options])
Generate an ETag for a string, ArrayBuffer view (a typed array such as Buffer, or a DataView), or file stats object. Only the bytes within the view are hashed. File stats can come from fs.stat or fs.statSync, with or without { bigint: true }. Strings and views generate strong ETags by default. File stats generate weak ETags by default. Use options.weak to override the default.
res.setHeader("ETag", etag(body));
Note: Use the same bigint setting when using fs.stat. Node.js can round modification times differently in the two modes, so the same file can produce different ETags.
Which bytes to hash
Hash the full selected representation as it would be sent in a 200 OK response. Use distinct strong ETags for different content codings, such as gzip and identity. HTTP chunk framing does not affect the ETag. A 206 Partial Content response uses the ETag of the full representation. See RFC 9110, Section 8.8.3.3 and Section 15.3.7.
Strings are hashed as UTF-8. If you send a string using another encoding, encode it once and use the same buffer for hashing and sending.
const body = Buffer.from("café", "latin1");
res.setHeader("ETag", etag(body));
res.end(body);
Options
etag accepts these properties in the options object.
weak
Specifies whether the generated ETag includes the weak validator mark (the leading W/). The actual entity tag is the same. The default is true for file stats and false for strings and ArrayBuffer views.
License
関連プロジェクトを探す
読み込み中…