Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

http: add abort event request() #9278

@cjihrig

Description

@cjihrig

There doesn't seem to be a good way (or at least I haven't found one) to detect when ClientRequest.prototype.abort() is called. There is ClientRequest.prototype.aborted, but that would require observing the object. It would be nice to have an abort event emitted in this case.

As a test case, I would like to detect the abort in the following code:

var assert = require('assert');
var http = require('http');
var server = http.createServer(function(req, res) {
  res.end();
});

server.listen(4000, function() {
  function connect(cb) {
    var req = http.request({
      port: 4000
    }, cb);

    return req;
  }

  var req = connect(function() {
    assert(false);
  });


  req.abort();
});

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions