发送标头后可以取消HTTP响应吗? [英] Can I cancel a HTTP response after headers are sent?
本文介绍了发送标头后可以取消HTTP响应吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在节点HTTP服务器上,我正在生成一个进程并将输出流式传输到响应。
On a node HTTP server I'm spawning a process and streaming the output to the response.
当进程返回时,我想向客户端指示如果发生错误。显然我无法设置HTTP状态代码,因为标题已经发送。
When the process returns I'd like to indicate to the client if an error occured. Obviously I can't set the HTTP status code as the headers were already sent.
有没有办法中止连接?
例如
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World\n');
// how do I abort the request at this point
// and indicate an error to the client?
// e.g. curl should return != 0
res.end();
}).listen(1337, '127.0.0.1');
推荐答案
我在 google groups ,您可以使用
-
req.client.destroy();
- 或
res.connection。 destroy();
- either
req.client.destroy();
- or
res.connection.destroy();
curl将报告
卷曲:(18)转移关闭,剩余未完成的读取数据
curl: (18) transfer closed with outstanding read data remaining
这篇关于发送标头后可以取消HTTP响应吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文