Skip to content
프로젝트

소개

간단한 HTTP ETag 생성

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
+1
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

etag

NPM Version NPM Downloads Node.js Version Build Status Coverage Status

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

MIT

관련 프로젝트 살펴보기

불러오는 중…