Koa always overwrite Content-Type for JSON responses (original) (raw)
const Koa = require('koa'); const app = new Koa(); app.use(ctx => { ctx.set('Content-Type', 'application/vnd.myapi.v1+json'); ctx.body = {message: 'hello'}; }); app.listen(3000);
When running this code I aways get Content-Type: application/json; charset=utf-8.
I can make it work if I write the header after setting the body. It only affects json responses. I'm not sure if that's a bug, but I couldn't find any information about that behavior in documentation.