How can I check if a req has a body without trying to parse it in the first place? #1348
-
Do you know if something like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi, @jjoselv. When handling requests on the web the only way you can check for a body without reading it is by reading the Strictly speaking, this is not an MSW-related question. Is there a particular use case you're trying to achieve with the library? If so, please share it, alongside your attempts to do so (code/reproduction repo). |
Beta Was this translation helpful? Give feedback.
Hi, @jjoselv.
When handling requests on the web the only way you can check for a body without reading it is by reading the
Content-Length
header sent in the response. All the other APIs require you to read the body. It makes sense, as body may be represented as a stream, and you have to read that stream to know if there's anything there at all.Strictly speaking, this is not an MSW-related question. Is there a particular use case you're trying to achieve with the library? If so, please share it, alongside your attempts to do so (code/reproduction repo).