0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/parallel/test-http-client-abort-keep-alive-queued-tcp-socket.js
Luigi Pinca eb2fbd159f
http: do not blindly destroy UNIX domain sockets
`Connection: keep-alive` is now properly supported when making client
connections to UNIX domain sockets so `request.abort()` should not
blindly destroy the underlying socket.

PR-URL: https://github.com/nodejs/node/pull/15650
Refs: https://github.com/nodejs/node/pull/13214#issuecomment-304049523
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
2017-10-23 12:13:03 -04:00

37 lines
838 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
let socketsCreated = 0;
class Agent extends http.Agent {
createConnection(options, oncreate) {
const socket = super.createConnection(options, oncreate);
socketsCreated++;
return socket;
}
}
const server = http.createServer((req, res) => res.end());
server.listen(0, common.mustCall(() => {
const port = server.address().port;
const agent = new Agent({
keepAlive: true,
maxSockets: 1
});
http.get({ agent, port }, (res) => res.resume());
const req = http.get({ agent, port }, common.mustNotCall());
req.abort();
http.get({ agent, port }, common.mustCall((res) => {
res.resume();
assert.strictEqual(socketsCreated, 1);
agent.destroy();
server.close();
}));
}));