From 95312af31a1addee8f79c1eccda712997abfb745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABrs=20Va=C4=BCenieks?= Date: Thu, 24 Nov 2016 11:38:17 +0200 Subject: [PATCH] Added IPv6 support. --- lib/client.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index e30c3b4..8725807 100644 --- a/lib/client.js +++ b/lib/client.js @@ -3,6 +3,7 @@ var https = require("https"); var json = require("./json"); var url = require("url"); var util = require("util"); +var os = require('os'); /*section: client *comment: | @@ -66,11 +67,21 @@ client.prototype.request = function(method, path, params, callback){ "query": query, }); + function is_ipv4_loop_back(interface0) { + // 169.254.xx.xx - loop back address for IPv4 + // if it exists all requests are redirected to localhost + return interface0.address.indexOf('169.254.') === 0; + } + + var isIPv6 = os.networkInterfaces().en0.find(is_ipv4_loop_back); + var family = isIPv6 ? 6 : 4; + var http_options = { hostname: this.api_host, port: 443, method: method.toUpperCase(), - path: path + path: path, + family: family }; if(this.proxy_agent){