Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
http: make socketPath work with no agent
Currently `Agent.prototype.createConnection()` is called uncoditionally
if the `socketPath` option is used. This throws an error if no agent is
used, preventing, for example, the `socketPath` and `createConnection`
options to be used together.

This commit fixes the issue by falling back to the `createConnection`
option or `net.createConnection()`.
  • Loading branch information
lpinca committed Mar 31, 2018
commit 6cc1820d95fb46f495074f011dc5fa035bf0133a
6 changes: 5 additions & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-http-client-unix-socket-no-agent.js
Original file line number Diff line number Diff line change
@@ -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();
}