Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-etag

Package Overview
Dependencies
Maintainers
7
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-etag - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

5

History.md
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);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc