fix Content-Type in cached response

This commit is contained in:
DIYgod
2019-01-17 15:55:34 +08:00
parent f134fac915
commit d64ca7b724
2 changed files with 10 additions and 6 deletions

View File

@@ -86,8 +86,10 @@ module.exports = function(options = {}) {
if (Buffer.isBuffer(type)) {
type = type.toString();
}
ctx.response.set('X-Koa-Memory-Cache', 'true');
ctx.response.type = type;
ctx.response.set({
'X-Koa-Memory-Cache': 'true',
'Content-Type': type,
});
try {
ctx.state.data = JSON.parse(value);
} catch (e) {
@@ -121,7 +123,7 @@ module.exports = function(options = {}) {
* cacheType
*/
async function cacheType(ctx, tkey) {
const type = ctx.response.type;
const type = ctx.response.headers['content-type'];
if (type) {
memoryCache.set(tkey, type);
}