5

I have an API written using the express framework. As part of the logging/scaling-tests process, I'd like to know how large a received request is in bytes (so we can determine the effect it's going to have on the network).

Is there a way of doing this? I've read through the Express Documentation and couldn't find anything. Will reading off the content-length header work? Or could that value be sent incorrectly?

user2110845
  • 385
  • 8
  • 19
  • Does this answer your question? [How to get byte size of request?](https://stackoverflow.com/questions/32295689/how-to-get-byte-size-of-request) – Rafael Tavares Oct 27 '21 at 16:32

1 Answers1

8

I have most commonly seen code using the content-length header, for example with req.get("content-length"). However I recently ran into a situation where that header wasn't provided, so I switched to using req.socket.bytesRead.

Carl
  • 374
  • 4
  • 8
  • 2
    what req.socket.bytesRead will give? I don't think it is giving req body size. I checked both for the same request "content-length" gave me 138421 and socket bytes - 65536 so I don't think they are same – Abhay Sehgal Feb 20 '20 at 05:58