diff --git a/lib/_http_client.js b/lib/_http_client.js index 9d2057814133b7..ea181cff31a482 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -138,7 +138,11 @@ function ClientRequest(options, cb) { timeout: self.timeout, rejectUnauthorized: !!options.rejectUnauthorized }; - const newSocket = self.agent.createConnection(optionsPath, oncreate); + const newSocket = self.agent + ? self.agent.createConnection(optionsPath, oncreate) + : typeof options.createConnection === 'function' + ? options.createConnection(optionsPath, oncreate) + : net.createConnection(optionsPath); if (newSocket && !called) { called = true; self.onSocket(newSocket); diff --git a/test/parallel/test-http-client-unix-socket-no-agent.js b/test/parallel/test-http-client-unix-socket-no-agent.js new file mode 100644 index 00000000000000..9dd11403c6bf79 --- /dev/null +++ b/test/parallel/test-http-client-unix-socket-no-agent.js @@ -0,0 +1,28 @@ +'use strict'; +const common = require('../common'); +const Countdown = require('../common/countdown'); + +const http = require('http'); +const { createConnection } = require('net'); + +const server = http.createServer((req, res) => { + res.end(); +}); + +const countdown = new Countdown(2, () => { + server.close(); +}); + +common.refreshTmpDir(); + +server.listen(common.PIPE, common.mustCall(() => { + http.get({ createConnection, socketPath: common.PIPE }, onResponse); + http.get({ agent: 0, socketPath: common.PIPE }, onResponse); +})); + +function onResponse(res) { + res.on('end', () => { + countdown.dec(); + }); + res.resume(); +}