Skip to content
Myr

add etag util

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent eec31d7 · Browse files · 2 files+20 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−4 removed

  • other:+20 added−4 removed

2 files+20 added−4 removed

modified:lib/response.js+4 added-3 removed
7 unmodified lines
8 , connect = require('connect')9 , utils = connect.utils10 , normalizeType = require('./utils').normalizeType11 , normalizeTypes = require('./utils').normalizeTypes12 , etag = require('./utils').etag13 , statusCodes = http.STATUS_CODES14 , send = connect.static.send15 , cookie = require('cookie')16 , send = require('send')
116 unmodified lines
133134 // ETag support135 // TODO: W/ support136 if (len > 1024) {136 if (!this.get('ETag')) this.set('ETag', Buffer.isBuffer(body)137 ? crc.buffer.crc32(body)138 : crc.crc32(body));137 if (!this.get('ETag')) {138 this.set('ETag', etag(body));139 }140 }141142 // freshness143 if (req.fresh) this.statusCode = 304;
536 unmodified lines
modified:lib/utils.js+16 added-1 removed
1 unmodified line
2/**3 * Module dependencies.4 */56var mime = require('connect').mime;6var mime = require('connect').mime7 , crc = require('crc');89/**10 * Return ETag for `body`.11 *12 * @param {String|Buffer} body13 * @return {String}14 * @api private15 */1617exports.etag = function(body){18 return Buffer.isBuffer(body)19 ? crc.buffer.crc32(body)20 : crc.crc32(body);21};2223/**24 * Make `locals()` bound to the given `obj`.25 * 26 * This is used for `app.locals` and `res.locals`. 27 *
257 unmodified lines