Comparing version 2.1.0 to 3.0.0
3.0.0 / 2016-02-27 | ||
================== | ||
* koa v2 support | ||
2.1.0 / 2015-10-27 | ||
@@ -3,0 +8,0 @@ ================== |
51
index.js
@@ -25,33 +25,36 @@ | ||
function etag(options) { | ||
return function *etag(next){ | ||
yield* next; | ||
return function etag(ctx, next) { | ||
return next() | ||
.then(() => getResponseEntity(ctx)) | ||
.then(entity => setEtag(ctx, entity, options)); | ||
}; | ||
} | ||
// no body | ||
var body = this.body; | ||
if (!body || this.response.get('ETag')) return; | ||
function getResponseEntity(ctx, options) { | ||
// no body | ||
var body = ctx.body; | ||
if (!body || ctx.response.get('ETag')) return; | ||
// type | ||
var status = this.status / 100 | 0; | ||
// type | ||
var status = ctx.status / 100 | 0; | ||
// 2xx | ||
if (2 != status) return; | ||
// 2xx | ||
if (2 != status) return; | ||
// hash | ||
var etag; | ||
if (body instanceof Stream) { | ||
if (!body.path) return; | ||
var s = yield fs.stat(body.path).catch(noop); | ||
if (!s) return; | ||
etag = calculate(s, options); | ||
} else if (('string' == typeof body) || Buffer.isBuffer(body)) { | ||
etag = calculate(body, options); | ||
} else { | ||
etag = calculate(JSON.stringify(body), options); | ||
} | ||
// add etag | ||
if (etag) this.response.etag = etag; | ||
if (body instanceof Stream) { | ||
if (!body.path) return; | ||
return fs.stat(body.path).catch(noop); | ||
} else if (('string' == typeof body) || Buffer.isBuffer(body)) { | ||
return body; | ||
} else { | ||
return JSON.stringify(body); | ||
} | ||
} | ||
function setEtag(ctx, entity, options) { | ||
if (!entity) return; | ||
ctx.response.etag = calculate(entity, options); | ||
} | ||
function noop() {} |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/etag", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"keywords": [ | ||
@@ -21,8 +21,12 @@ "koa", | ||
"devDependencies": { | ||
"eslint": "^2.2.0", | ||
"eslint-config-standard": "^5.1.0", | ||
"eslint-plugin-promise": "^1.0.8", | ||
"eslint-plugin-standard": "^1.3.2", | ||
"istanbul": "^0.4.0", | ||
"koa": "*", | ||
"should": "3", | ||
"mocha": "2", | ||
"supertest": "0", | ||
"koa-static": "1" | ||
"koa": "^2.0.0-alpha.3", | ||
"koa-static": "^2.0.0", | ||
"mocha": "^2.0.0", | ||
"should": "^8.0.2", | ||
"supertest": "^1.1.0" | ||
}, | ||
@@ -32,5 +36,6 @@ "license": "MIT", | ||
"etag": "^1.3.0", | ||
"mz": "^1.0.0" | ||
"mz": "^2.1.0" | ||
}, | ||
"scripts": { | ||
"lint": "eslint index.js test", | ||
"test": "mocha --harmony --reporter spec --require should", | ||
@@ -37,0 +42,0 @@ "test-cov": "node --harmony node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should", |
@@ -31,8 +31,5 @@ | ||
app.use(function(next){ | ||
return function *(){ | ||
yield next; | ||
this.body = 'Hello World'; | ||
} | ||
}) | ||
app.use(function(ctx) { | ||
ctx.body = 'Hello World'; | ||
}); | ||
@@ -39,0 +36,0 @@ app.listen(3000); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5006
46
0
10
60
+ Addedmz@2.7.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
- Removedmz@1.3.0(transitive)
- Removednative-or-bluebird@1.2.0(transitive)
Updatedmz@^2.1.0