koajs / etag Goto Github PK
View Code? Open in Web Editor NEWETag support for Koa responses
License: MIT License
ETag support for Koa responses
License: MIT License
Hey guys,
I have following route:
// Get color
module.exports.get = async(ctx) => {
console.log(ctx.fresh);
ctx.body = await colors.findOne({
_id: ctx.params.id
});
if (!ctx.body) {
ctx.throw(404);
}
};
I now want to make use of etags so I added:
app.use(conditional());
app.use(etag());
Now I see that etag header is automatically added when I perform the get request: ETag:"59-tTS1BcOQRvGxbONr3n6C5Q"
When I now add If-None-Match: "59-tTS1BcOQRvGxbONr3n6C5Q"
to the request I always get 200 instead if 304.
if (ctx.fresh) {}
always returns false. Am I missing somethong?
If the order of use of "koa-compress" and "koa-etag" is reversed, "etag" will not take effect.
Because "koa-etag" cannot handle it, if "ctx.body" is a "stream" compressed by "koa-compress" without ".path".
etag = crc(s.size + '.' + s.mtime);
is that on purpose? all your other libs do size + '-' + mtime
basically
should be renamed IMO
would be nice if this module allowed the etag to be set both through this
and as middleware.
app.context(require('koa-etag'))
app.use(function (next) {
return function* () {
this.body = 'something'
this.setETag()
}
})
or something
In v2.x(as well as v3),When response body is huge, JSON.stringify throw RangeError: Invalid string length
. So,
etag = calculate(JSON.stringify(body), options);
add simple try...catch will be ok?
try {
etag = calculate(JSON.stringify(body), options);
} catch (e) {}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.