Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 21, 2012
2 parents c852693 + 763be5e commit e2ad0d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 2 additions & 4 deletions lib/utils.js
Expand Up @@ -4,7 +4,7 @@
*/

var mime = require('connect').mime
, crc = require('crc');
, crc32 = require('buffer-crc32');

/**
* Return ETag for `body`.
Expand All @@ -15,9 +15,7 @@ var mime = require('connect').mime
*/

exports.etag = function(body){
return '"' + (Buffer.isBuffer(body)
? crc.buffer.crc32(body)
: crc.crc32(body)) + '"';
return '"' + crc32.signed(body) + '"';
};

/**
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -3,8 +3,8 @@
"description": "Sinatra inspired web development framework",
"version": "3.0.3",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
{ "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
"contributors": [
{ "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
{ "name": "Aaron Heckmann", "email": "aaron.heckmann+github@gmail.com" },
{ "name": "Ciaran Jessup", "email": "ciaranj@gmail.com" },
{ "name": "Guillermo Rauch", "email": "rauchg@gmail.com" }
Expand All @@ -15,7 +15,7 @@
"range-parser": "0.0.4",
"mkdirp": "0.3.3",
"cookie": "0.0.5",
"crc": "0.2.0",
"buffer-crc32": "0.1.1",
"fresh": "0.1.0",
"methods": "0.0.1",
"send": "0.1.0",
Expand Down
20 changes: 20 additions & 0 deletions test/utils.js
Expand Up @@ -2,6 +2,26 @@
var utils = require('../lib/utils')
, assert = require('assert');

describe('utils.etag(body)', function(){

var str = 'Hello CRC';
var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';

it('should support strings', function(){
utils.etag(str).should.eql('"-2034458343"');
})

it('should support utf8 strings', function(){
utils.etag(strUTF8).should.eql('"1395090196"');
})

it('should support buffer', function(){
utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');
utils.etag(new Buffer(str)).should.eql('"-2034458343"');
})

})

describe('utils.isAbsolute()', function(){
it('should support windows', function(){
assert(utils.isAbsolute('c:\\'));
Expand Down

0 comments on commit e2ad0d3

Please sign in to comment.