fix Content-Type in cached response
This commit is contained in:
parent
f134fac915
commit
d64ca7b724
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,8 +107,10 @@ module.exports = function(options = {}) {
|
|||
if (Buffer.isBuffer(type)) {
|
||||
type = type.toString();
|
||||
}
|
||||
ctx.response.set('X-Koa-Redis-Cache', 'true');
|
||||
ctx.response.type = type;
|
||||
ctx.response.set({
|
||||
'X-Koa-Redis-Cache': 'true',
|
||||
'Content-Type': type,
|
||||
});
|
||||
try {
|
||||
ctx.state.data = JSON.parse(value);
|
||||
} catch (e) {
|
||||
|
|
@ -142,7 +144,7 @@ module.exports = function(options = {}) {
|
|||
* cacheType
|
||||
*/
|
||||
async function cacheType(ctx, tkey, expire) {
|
||||
const type = ctx.response.type;
|
||||
const type = ctx.response.headers['content-type'];
|
||||
if (type) {
|
||||
await redisClient.setex(tkey, expire, type);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue