-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto generate ETag & freshness check #92
Conversation
Freshness checkReturn 304 if fresh. module.exports = {
name: "rss",
actions: {
feed(ctx) {
ctx.meta.$responseHeaders = {
"Last-Modified": "Tue, 24 Feb 2018 08:01:04 GMT"
}
return rssFeed
},
async getItem(ctx){
let item = await getRssItem(ctx.params.id)
ctx.meta.$responseHeaders = {
"ETag": item.hash
}
return item
}
}
} Auto generate etagService settings: settings: {
etag: true
} Will only generate ETag for none stream response. If you want to stream your response, you should generate the etag by yourself. module.exports = {
name: "export",
actions: {
// Download response as a file in the browser
downloadCSV(ctx) {
ctx.meta.$responseType = "text/csv";
ctx.meta.$responseHeaders = {
"Content-Disposition": `attachment; filename="data-${ctx.params.id}.csv"`,
"ETag": '<your etag here>'
};
return csvFileStream;
}
} |
Great, thank you! Please cover this ETag functionality with tests. |
fix multipart
Pull Request Test Coverage Report for Build 360
💛 - Coveralls |
Thanks @tiaod,
|
@icebob I‘m just trying to do what express do by default. See doc
//Boolean
settings: {
routes: [{
path: "/",
etag: true
}]
},
//String
settings: {
routes: [{
path: "/",
etag: "weak" // or "strong"
}]
},
// Function
settings: {
routes: [{
path: "/",
etag: function(body, encoding) {
return generateHash(body, encoding); // consider the function is defined
}
}]
} Btw: HTTP ETag strong and weak validation from wikipedia:
|
Ok, we can change it to express-like, but if you check the source of |
I've updated. So now it has the following values:
And you can set it in service settings and route setting as well. Route setting overwrites service setting. |
I'm living in GMT+8 and good morning! 😄 I think the weak mode of
After some search, I found the difference between the strong and weak ETag:
But I am still very confused which should I use. 😅 Finally, I decided to follow the express, to use the weak etag by default. Do what express do is right! |
Excuse me guys but why no |
Cache-Control & ETag are two different caching solutions. Using ETag, no need Cache-Control headers. |
Fix #91