Liked title described, I tried to use chunked response (multiple res.write()
) in Node.js with Express:
res.header('Transfer-Encoding', 'chunked');
// Different JSON object arrived at different time,
// so I cannot or I don't want to combine them at certain point...
res.write(JSON.stringify(jsonObjA));
res.write(JSON.stringify(jsonObjB));
res.write(JSON.stringify(jsonObjC));
res.end();
Then the http client I am using is axios, which the response I got is just simply combined big string, there is no \r\n
appended after each chunk like described here: Transfer-Encoding: chunked, so I have no way to parse the response.
So:
- Where I am doing wrongly?
- Or I need to append
\r\n
manually after each chunk? - How to do the
response.on('data', () => {})
so I can listen on each chunk in axios?
via lnshi
No comments:
Post a Comment