为何我将content-type设置为image/jpeg后无法存储cookie?
import Koa from "koa";
import Router from "koa-router";
import request from "supertest";
const app = new Koa();
const router = new Router();
const client = request.agent(app.listen(3000));
router
.get("/", async (ctx, next) => {
try {
let cv = ctx.cookies.get('temp');
if (cv) {
console.log(cv)//第二次请求没有获取到cookie的值,cookie没有存储,可能是content-type设置有误
ctx.type = 'image/jpeg';
ctx.body = '233';//原本是一个buffer类型数据,这里简略
ctx.status = 200;
} else {
await ctx.cookies.set('temp', '123456', {maxAge: 99999});
ctx.type = 'image/jpeg';
ctx.body = '233';
ctx.status = 200;
}
} catch (e) {
console.log(e)
ctx.status = 400;
}
})
app
.use(router.routes())
.use(router.allowedMethods());
describe("test", () => {
it("1", done => {
client
.get('/')
.expect(200, (err, res) => {
if (err) {
done(err)
} else {
//第一请求是header里有set-cookie
cookie = res.header["set-cookie"][0];
console.log(cookie);
done()
}
})
});
it("2", done => {
client
.get('/')
.expect(200, done)
});
})
而我将content-type改为其他类型后,却能正确存储了。 content-type设置为image/jpeg 是有什么问题吗? 我查校过是有image/jpeg这个content-type的。