Request pending forever if content type is application/json
See original GitHub issueProblem/Feature Request Summary
Not able to parse request body when the header is application/json
Environment Information
- koa-body: 4.1.0
- Koa: 2.7.0
- Node.js: 12.4.0
- koa-router: 7.4.0
Current Behavior
When request Content-Type header is application/json the request stay pending forever resolving. ,
Steps to Reproduce
const Router = require(“koa-router”); const koaBody = require(“koa-body”)
Expected Behavior
application/json content parsed
Context (Environment)
For urlencoded or text request its working fine.
I tried to debug it and I can see the options passed to the co-body json https://github.com/dlau/koa-body/blob/ed81445ccd6d2e3b5e4605ce502b60c75386f8f5/index.js#L74 are:
{
encoding: 'utf-8',
limit: '1mb',
strict: true,
returnRawBody: false
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
node.js - Patch request is forever stuck on pending
On triggering the event that leads to the request on the front end; My network has two items : A preflight with status...
Read more >chrome requests get stuck pending - nginx - Server Fault
If it's stuck waiting for the end of the content, it means the web server fully received and processed the request, you should...
Read more >Pending Client Certificate List REST Service - IBM
The processing of the request fails because of an unexpected condition on the server. Content-Type, application/json. Content-Language, Locale for the response ...
Read more >Request stuck in pending state / promise never resolves #941
If I add logs in the "response" callback and the requestPromise.then() , I'll see both of them, indicating that the promise created by...
Read more >How to Cancel Pending API Requests to Show Correct Data
One problem quickly became evident: if the user clicked around fast enough, as previous network requests got resolved, the UI was updated ...
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
I can confirm we’re experiencing this as well, but I should note that this only happens when we deploy to Google Cloud Functions, running locally works fine.
Reproducing this is pretty simple:
In postman if you enable the header
Content-Type: application/json
it hangs forever, but if you take it out then it responds immediately.Decided to spend some time and dig into this and was able to replicate it on the functions emulator.
Looks to be an issue with the
ctx.req
stream already being “read” and theraw-body
dep doesn’t handle that, see here:https://github.com/stream-utils/raw-body/issues/57 https://github.com/stream-utils/raw-body/pull/58
Not sure what the solution is here though to actually get
koa-body
access to that data though…