Handle body when it's already parsed
See original GitHub issueMoved from #5
The problem is that we really do not know how req.body
has been parsed by just checking its type (e.g. Firebase Cloud Functions). It’s straight forward when its type is string, but things go difficult when it’s an object
. Calling .toString()
cannot be a silver bullet as we do not know how it’s implemented. If it results in a different string from the original request body, the validation process will silently fail which I do not want to happen.
I will first make it work with a string and a buffer, and look into how an object can be handled. Any idea is welcomed.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Node.js - Handle body-parser invalid JSON error
When a valid input like { "foo": "bar" } is received everything works fine and I can access the parsed object with req.body...
Read more >Express body-parser middleware
Returns middleware that parses all bodies as a Buffer and only looks at requests where the Content-Type header matches the type option. This...
Read more >Read and parse POST/PATCH/PUT request JSON or form ...
Read and parse POST/PATCH/PUT request JSON or form body with Express and no dependencies. When asked to handle data in a request body, ......
Read more >Express JS— body-parser and why may not need it
Node/Express This piece of middleware was called body-parser and used to not be part of the Express framework. The good news is that...
Read more >Creating a REST API with Node.js - YouTube
Let's parse our request body, so that our RESTful API can receive and use data. And handle CORS to allow other clients to...
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
After internal review, we decide to reject this PR as it’s not very safe to support this kind of option. There cannot be a silver-bullet function to revert an object into the original body buffer.
Rather than this, the case should be handled by using the
validateSignature()
function directly.Great news! Let’s do this.