Koa always overwrite `Content-Type` for JSON responses
See original GitHub issueconst 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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Content-type header is always the same while testing koa ...
When testing routes with supertest I face a problem, that content-type response header is always application/json; charset=utf-8 . const app = ...
Read more >Receiving Requests with Koa
Koa is a small framework that lets us create backend apps that run on the Node.js platform. In this article, we'll look at...
Read more >Koa - next generation web framework for node.js
A Koa Context encapsulates node's request and response objects into a single object ... 'text/html' // When Content-Type is application/json ctx.is('json', ...
Read more >Koa.js - Quick Guide
Step 3 − Now we have our package.json file set up, we'll install Koa. To install Koa and add it in ... Get...
Read more >Express 5.x - API Reference
Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option. This parser accepts any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
seems like a bug where it overwrites the content type when the content type is set and has
+json
in it.Check if body has value of type object, and if the header contains
+json
preserve the user given header. Is this the desired implementation of fix for this bug?