question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom middleware request body gets overriden

See original GitHub issue

I have custom middleware that appends request body and puts some value there. But when is form-data, that appended value dissapears from request body. I did a bit of investigation around and i found why.

In multer file lib/make-middleware.js at line 27, there is this piece of code req.body = Object.create(null) which destroys previous set values by my middleware. I simply commented this and solved problem for me. I didn’t go further to investigate why this piece of code exists and purpose of it.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Spowncommented, Feb 1, 2017

in any case it wouldn’t harm to extend the existing .body with your body instead of overwriting. if the fields with same name appear in the form-data request - they will be overwritten as before, isn’t it?

1reaction
george3447commented, Jun 8, 2020

Hi @jonchurch , I have created a PR, could you please review it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rewind request body stream - asp.net - Stack Overflow
Just found one solution. Replacing the original stream with a new stream containing the data. public override async Task Invoke(IOwinContext ...
Read more >
Use Custom Middleware to Detect and Fix 404s in ASP.NET ...
To do that, I create a service called RequestTracker that records instances of 404 requests based on their path. RequestTracker is passed into...
Read more >
Method Override Middleware | Echo - High performance ...
Method override middleware checks for the overridden method from the request and uses it instead of the original method. For security reasons, only...
Read more >
Middleware - FastAPI
A "middleware" is a function that works with every request before it is processed by any specific path operation. And also with every...
Read more >
Express body-parser middleware
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ). This will be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found