我正在寻找解决方案,以监控 http response.write 方法的发送/写入过程。
当事件(在我的情况下是带有安全令牌的第二个请求)出现(或不出现)时,我希望能够监视和停止正在运行的进程。
这通常是可能的吗,如果是这样,是否有人对我有一些和平的代码?
这是代码行的咖啡片段
if req.headers.range?
console.log "serve range request from cache"
# browser wants chunged transmission
range = req.headers.range
parts = range.replace(/bytes=/, "").split "-"
partialstart = parts[0]
partialend = parts[1]
total = file.length
start = parseInt partialstart, 10
end = if partialend then parseInt partialend, 10 else total - 1
header["Content-Range"] = "bytes #{start}-#{end}/#{total}"
header["Accept-Ranges"] = "bytes"
header["Content-Length"]= (end-start)+1
header['Transfer-Encoding'] = 'chunked'
header["Connection"] = "close"
res.writeHead 206, header
# yeah I dont know why i have to append the '0'
# but chrome wont work unless i do
res.write file.slice(start, end)+'0', "binary"
else
console.log "serve normal request from cache"
# reply to normal un-chunked request
res.writeHead 200, header
res.write file, "binary"
console.log err if err
res.end()
有没有办法将res.write 文件,“二进制”行包装在某种函数或进程中,可以被杀死?
亲切的问候