morgan-body icon indicating copy to clipboard operation
morgan-body copied to clipboard

If body is really big, morgan-body takes a LONG time even when maxBodyLength is set

Open mkausas opened this issue 4 years ago • 5 comments

Noting this as a point of improvement. I was sending post requests with really large bodies and even though I had set maxBodyLength, morgan-body was taking 30+ seconds to parse and print the request body.

I haven't looked into why this is happening, but I thought I'd mention it.

If helpful for others, I temporarily disabled the couple endpoints this was affecting by using the skip option for those endpoints to not log the request body.

function skipCriteria(req, res) {
  if (
    req.baseUrl === "/users/log" &&
    req.method === "POST"
  ) {
    return true;
  }

  return false;
}
  morganBody(app, {
    skip: skipCriteria,
  });

mkausas avatar Oct 07 '20 20:10 mkausas

Afaik, this issue should be fixed in v3, which is getting released soon, see PR #39

Could you give us more steps on how to reproduce this issue so we can take a deeper look into it?

Thanks in advance.

VottusCode avatar Oct 08 '20 15:10 VottusCode

hmmm simplest way to deal with this would be to set a maximum size and not log the body if it's over that...

how long did it take? @mkausas

sirrodgepodge avatar Nov 06 '20 18:11 sirrodgepodge

The body was about 1.5mb. It was sometimes taking 30+ seconds.

mkausas avatar Nov 06 '20 23:11 mkausas

@VottusCode to reproduce send some large bodies with a post request. You can check the size of the request with one line to test out the 1.5mb: https://stackoverflow.com/questions/39653904/get-size-of-request

mkausas avatar Nov 06 '20 23:11 mkausas

@VottusCode to reproduce send some large bodies with a post request. You can check the size of the request with one line to test out the 1.5mb: https://stackoverflow.com/questions/39653904/get-size-of-request

I will take a look in this soon. Thank you.

VottusCode avatar Nov 10 '20 19:11 VottusCode