From 85a48b2eaaae185f98dec8ef83d14db5332d11e1 Mon Sep 17 00:00:00 2001 From: Starfox64 Date: Mon, 4 Sep 2017 17:06:19 +0200 Subject: [PATCH] Adding support for UNIX Sockets --- README.md | 4 ++++ lib/adapters/http.js | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 lib/adapters/http.js diff --git a/README.md b/README.md old mode 100644 new mode 100755 index c3d16c139e..4bf0f42aec --- a/README.md +++ b/README.md @@ -312,6 +312,10 @@ These are the available config options for making requests. Only the `url` is re // If set to 0, no redirects will be followed. maxRedirects: 5, // default + // `socketPath` defines a UNIX Socket to be used in node.js. + // e.g. '/var/run/docker.sock' to send requests to the docker daemon. + socketPath: null, // default + // `httpAgent` and `httpsAgent` define a custom agent to be used when performing http // and https requests, respectively, in node.js. This allows options to be added like // `keepAlive` that are not enabled by default. diff --git a/lib/adapters/http.js b/lib/adapters/http.js old mode 100644 new mode 100755 index af2f59dcd1..3fde8cc36b --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -72,8 +72,6 @@ module.exports = function httpAdapter(config) { var agent = isHttps ? config.httpsAgent : config.httpAgent; var options = { - hostname: parsed.hostname, - port: parsed.port, path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''), method: config.method, headers: headers, @@ -81,6 +79,13 @@ module.exports = function httpAdapter(config) { auth: auth }; + if (config.socketPath) { + options.socketPath = config.socketPath; + } else { + options.hostname = parsed.hostname; + options.port = parsed.port; + } + var proxy = config.proxy; if (!proxy && proxy !== false) { var proxyEnv = protocol.slice(0, -1) + '_proxy';