• Stars
    star
    251
  • Rank 161,862 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create simple HTTP ETags

etag

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

Create simple HTTP ETags

This module generates HTTP ETags (as defined in RFC 7232) for use in HTTP responses.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install etag

API

var etag = require('etag')

etag(entity, [options])

Generate a strong ETag for the given entity. This should be the complete body of the entity. Strings, Buffers, and fs.Stats are accepted. By default, a strong ETag is generated except for fs.Stats, which will generate a weak ETag (this can be overwritten by options.weak).

res.setHeader('ETag', etag(body))

Options

etag accepts these properties in the options object.

weak

Specifies if the generated ETag will include the weak validator mark (that is, the leading W/). The actual entity tag is the same. The default value is false, unless the entity is fs.Stats, in which case it is true.

Testing

$ npm test

Benchmark

$ npm run-script bench

> [email protected] bench nodejs-etag
> node benchmark/index.js

  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  modules@48
  [email protected]

> node benchmark/body0-100b.js

  100B body

  4 tests completed.

  buffer - strong x 258,647 ops/sec ±1.07% (180 runs sampled)
  buffer - weak   x 263,812 ops/sec ±0.61% (184 runs sampled)
  string - strong x 259,955 ops/sec ±1.19% (185 runs sampled)
  string - weak   x 264,356 ops/sec ±1.09% (184 runs sampled)

> node benchmark/body1-1kb.js

  1KB body

  4 tests completed.

  buffer - strong x 189,018 ops/sec ±1.12% (182 runs sampled)
  buffer - weak   x 190,586 ops/sec ±0.81% (186 runs sampled)
  string - strong x 144,272 ops/sec ±0.96% (188 runs sampled)
  string - weak   x 145,380 ops/sec ±1.43% (187 runs sampled)

> node benchmark/body2-5kb.js

  5KB body

  4 tests completed.

  buffer - strong x 92,435 ops/sec ±0.42% (188 runs sampled)
  buffer - weak   x 92,373 ops/sec ±0.58% (189 runs sampled)
  string - strong x 48,850 ops/sec ±0.56% (186 runs sampled)
  string - weak   x 49,380 ops/sec ±0.56% (190 runs sampled)

> node benchmark/body3-10kb.js

  10KB body

  4 tests completed.

  buffer - strong x 55,989 ops/sec ±0.93% (188 runs sampled)
  buffer - weak   x 56,148 ops/sec ±0.55% (190 runs sampled)
  string - strong x 27,345 ops/sec ±0.43% (188 runs sampled)
  string - weak   x 27,496 ops/sec ±0.45% (190 runs sampled)

> node benchmark/body4-100kb.js

  100KB body

  4 tests completed.

  buffer - strong x 7,083 ops/sec ±0.22% (190 runs sampled)
  buffer - weak   x 7,115 ops/sec ±0.26% (191 runs sampled)
  string - strong x 3,068 ops/sec ±0.34% (190 runs sampled)
  string - weak   x 3,096 ops/sec ±0.35% (190 runs sampled)

> node benchmark/stats.js

  stat

  4 tests completed.

  real - strong x 871,642 ops/sec ±0.34% (189 runs sampled)
  real - weak   x 867,613 ops/sec ±0.39% (190 runs sampled)
  fake - strong x 401,051 ops/sec ±0.40% (189 runs sampled)
  fake - weak   x 400,100 ops/sec ±0.47% (188 runs sampled)

License

MIT

More Repositories

1

http-errors

Create HTTP Errors
JavaScript
1,489
star
2

mime-types

The ultimate javascript content-type utility.
JavaScript
1,311
star
3

cookie

HTTP server cookie parsing and serialization
JavaScript
1,303
star
4

mime-db

Media Type Database
JavaScript
1,083
star
5

basic-auth

Generic basic auth Authorization header field parser
JavaScript
704
star
6

on-finished

Execute a callback when a request closes, finishes, or errors
JavaScript
389
star
7

negotiator

An HTTP content negotiator for Node.js
JavaScript
307
star
8

statuses

HTTP status utility
JavaScript
269
star
9

accepts

Higher-level content negotiation
JavaScript
252
star
10

type-is

Infer the content-type of a request.
JavaScript
226
star
11

content-disposition

Create and parse HTTP Content-Disposition header
JavaScript
220
star
12

methods

HTTP verbs that node supports
JavaScript
177
star
13

fresh

HTTP request freshness testing
JavaScript
159
star
14

on-headers

Execute a listener when a response is about to write headers.
JavaScript
154
star
15

http-assert

assert with status codes
JavaScript
151
star
16

proxy-addr

Determine address of proxied request
JavaScript
132
star
17

content-type

Create and parse HTTP Content-Type header
JavaScript
130
star
18

style-guide

jshttp style guide
JavaScript
108
star
19

compressible

Compressible Content-Type / mime checking.
JavaScript
98
star
20

range-parser

Range header field parser
JavaScript
90
star
21

vary

Manipulate the HTTP Vary header
JavaScript
61
star
22

forwarded

Parse HTTP X-Forwarded-For header
JavaScript
56
star
23

media-typer

Simple RFC 6838 media type parser and formatter
JavaScript
54
star
24

jshttp.github.io

HTML
47
star
25

spdy-push

SPDY Push helper - will by replaced by http-push
JavaScript
29
star
26

http-push

14
star
27

http-utils

Low-level HTTP parsing/formatting utilities
JavaScript
14
star
28

.github

1
star