the request contained 'Expect: 100-continue'. This is an instruction that
the client should send the request body.
+### Event: 'abort'
+
+`function () { }`
+
+Emitted when the request has been aborted by the client. This event is only
+emitted on the first call to `abort()`.
+
### request.flush()
Flush the request headers.
};
ClientRequest.prototype.abort = function() {
+ var self = this;
+ if (this.aborted === undefined) {
+ process.nextTick(function() {
+ self.emit('abort');
+ });
+ }
// Mark as aborting so we can avoid sending queued request data
// This is used as a truthy flag elsewhere. The use of Date.now is for
// debugging purposes only.
--- /dev/null
+var assert = require('assert');
+var http = require('http');
+var common = require('../common');
+var server = http.createServer(function(req, res) {
+ res.end();
+});
+var count = 0;
+server.listen(common.PORT, function() {
+ var req = http.request({
+ port: common.PORT
+ }, function() {
+ assert(false, 'should not receive data');
+ });
+
+ req.on('abort', function() {
+ // should only be emitted once
+ count++;
+ server.close();
+ });
+
+ req.end();
+ req.abort();
+ req.abort();
+});
+
+process.on('exit', function() {
+ assert.equal(count, 1);
+})