Connect or Express middleware to modify the response.body

前端 未结 5 1539
一个人的身影
一个人的身影 2020-12-03 02:21

I would like to have a middleware function which modifies the response body.

This is for an express server.

Something like:

function modify(         


        
5条回答
  •  被撕碎了的回忆
    2020-12-03 03:03

    I believe the OP actually wants to modify the response stream once a middleware has handled the request. Look at the bundled Compress middleware implementation for an example of how this is done. Connect monkey patches the ServerResponse prototype to emit the header event when writeHead is called, but before it is completed.

提交回复
热议问题