Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] http: make socketPath work with no agent #19489

Closed
wants to merge 1 commit into from
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
8 changes: 7 additions & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ function ClientRequest(options, cb) {
if (self.socketPath) {
self._last = true;
self.shouldKeepAlive = false;
self.onSocket(self.agent.createConnection({ path: self.socketPath }));
var opts = { path: self.socketPath };
var socket = self.agent
? self.agent.createConnection(opts)
: options.createConnection
? options.createConnection(opts)
: net.createConnection(opts);
self.onSocket(socket);
} else if (self.agent) {
// If there is an agent we should default to Connection:keep-alive,
// but only if the Agent will actually reuse the connection!
Expand Down
22 changes: 22 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,22 @@
'use strict';
const common = require('../common');

const http = require('http');
const net = require('net');

let requests = 0;
const server = http.createServer((req, res) => {
if (++requests === 2)
server.close();
res.end();
});

common.refreshTmpDir();

server.listen(common.PIPE, common.mustCall(() => {
http.get({
createConnection: net.createConnection,
socketPath: common.PIPE
});
http.get({ agent: 0, socketPath: common.PIPE });
}));