Check if res is sent / ended with Express

China☆狼群 提交于 2021-01-28 18:20:41

问题


Using Express, how can I determine the response has been sent / that the response has been completely written to?

app.use((req,res,next) => {

   if(res.ended){
     //
   }

   if(res.finished){
     //
   }

});

how can I tell if res.end() has been called? I am looking for a boolean I can read on res.


回答1:


response.end() will set response.finished if it's been called, as per the documentation.




回答2:


Use res.writableEnded (docs).

res.finished is deprecated (see).



来源:https://stackoverflow.com/questions/57618325/check-if-res-is-sent-ended-with-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!