From f423ec90fc6cfa47baf48485240dd338d61e9307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 20 Feb 2011 13:31:37 +0100 Subject: [PATCH] In addition to 'aborted' emit 'close' from incoming requests Closes GH-160. --- lib/http.js | 1 + test/simple/test-http-response-close.js | 34 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/simple/test-http-response-close.js diff --git a/lib/http.js b/lib/http.js index 8313c8cc64..5e86a33f0d 100644 --- a/lib/http.js +++ b/lib/http.js @@ -952,6 +952,7 @@ function connectionListener(socket) { while (incoming.length) { var req = incoming.shift(); req.emit('aborted'); + req.emit('close'); } // abort socket._httpMessage ? } diff --git a/test/simple/test-http-response-close.js b/test/simple/test-http-response-close.js new file mode 100644 index 0000000000..7a1b76e299 --- /dev/null +++ b/test/simple/test-http-response-close.js @@ -0,0 +1,34 @@ +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); + +var gotEnd = false; + +var server = http.createServer(function(req, res) { + res.writeHead(200); + res.write('a'); + + req.on('close', function() { + console.error("aborted"); + gotEnd = true; + }); +}); +server.listen(common.PORT); + +server.addListener('listening', function() { + console.error("make req"); + http.get({ + port: common.PORT + }, function(res) { + console.error("got res"); + res.on('data', function(data) { + console.error("destroy res"); + res.destroy(); + server.close(); + }); + }); +}); + +process.on('exit', function() { + assert.ok(gotEnd); +});