Comparing version 1.1.0 to 1.2.1
52
index.js
@@ -24,37 +24,35 @@ | ||
function etag() { | ||
return function(next){ | ||
return function *(){ | ||
yield next; | ||
return function *(next){ | ||
yield next; | ||
// no body | ||
var body = this.body; | ||
if (!body) return; | ||
// no body | ||
var body = this.body; | ||
if (!body) return; | ||
// type | ||
var status = this.status / 100 | 0; | ||
var type = typeof body; | ||
var etag; | ||
// type | ||
var status = this.status / 100 | 0; | ||
var type = typeof body; | ||
var etag; | ||
// 2xx | ||
if (2 != status) return; | ||
// 2xx | ||
if (2 != status) return; | ||
// stream | ||
if (body instanceof Stream) { | ||
if (!body.path) return; | ||
var s = yield stat(body.path); | ||
etag = crc(s.size + '.' + s.mtime); | ||
} | ||
// stream | ||
if (body instanceof Stream) { | ||
if (!body.path) return; | ||
var s = yield stat(body.path); | ||
etag = crc(s.size + '.' + s.mtime); | ||
} | ||
// string | ||
if ('string' == type) etag = crc(body); | ||
// string | ||
if ('string' == type) etag = crc(body); | ||
// buffer | ||
if (Buffer.isBuffer(body)) etag = crc(body); | ||
// buffer | ||
if (Buffer.isBuffer(body)) etag = crc(body); | ||
// json | ||
etag = crc(JSON.stringify(body)); | ||
// json | ||
etag = crc(JSON.stringify(body)); | ||
// add etag | ||
if (etag) this.set('ETag', '"' + etag + '"'); | ||
} | ||
// add etag | ||
if (etag) this.set('ETag', '"' + etag + '"'); | ||
} | ||
@@ -61,0 +59,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/etag", | ||
"version": "1.1.0", | ||
"version": "1.2.1", | ||
"keywords": [ | ||
@@ -21,6 +21,7 @@ "koa", | ||
"devDependencies": { | ||
"koa": "0.0.1", | ||
"koa": "koajs/koa", | ||
"should": "~1.2.2", | ||
"mocha": "~1.12.0", | ||
"supertest": "~0.7.1" | ||
"supertest": "~0.7.1", | ||
"koa-static": "1.3.0" | ||
}, | ||
@@ -27,0 +28,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1934
5
51