I have an express middleware that has its own write
function on the response object. I am capturing the response bodies for use elsewhere. I am using body.toString()
to capture the body.
However, some of the response bodies are malformed in out output. For example I might capture:
'\u001f�\b\u0000\u000fb\u0007T\u0000\u0003�WɎ�6\u0010�\u0015E�\\�nR�|ʆ\u0004Y\u000f�\u00009\u0004�@K��iJTH�...'
When the server is actually responding with a JSON object. I'm guessing there is an encoding issue here. Any help on resolving? I have tried body.toString("utf8")
with no luck.
Update: showing the code:
function(req, res, next) {
var write = res.write;
res.write = function(body) {
var rawBody = body.toString();