diff --git a/README.md b/README.md index 3a375ab6b..46fe5fd74 100644 --- a/README.md +++ b/README.md @@ -609,16 +609,18 @@ To run tests, you need to generate a self-signed SSL certificate in the `test` d $ openssl req -new -key test/keys/ssl.key -x509 -days 999 -out test/keys/ssl.cert Then you should be able to run `npm test` once you have the dependencies in place. +To run the tests with debug logs, set the environment variable `NODE_DEBUG` to `needle` (for example, by running `NODE_DEBUG=needle npm test`). > Note: Tests currently only work on linux-based environments that have `/proc/self/fd`. They *do not* work on MacOS environments. > You can use Docker to run tests by creating a container and mounting the needle project directory on `/app` -```bash -# Located in your local cloned project : -docker run -it -w /app --name Needle \ ---mount type=bind,source="$(pwd)",target=/app \ -node:fermium bash -``` + docker create --name Needle -v $(pwd) -w /app -v $(pwd)/node_modules -i node:argon + +Or alternatively: + + docker run -it -w /app --name Needle \ + --mount type=bind,source="$(pwd)",target=/app \ + node:fermium bash Credits ------- diff --git a/lib/needle.js b/lib/needle.js index df5f1264f..004366c52 100644 --- a/lib/needle.js +++ b/lib/needle.js @@ -10,7 +10,7 @@ var fs = require('fs'), https = require('https'), url = require('url'), stream = require('stream'), - debug = require('debug')('needle'), + debug = require('util').debuglog('needle'), stringify = require('./querystring').build, multipart = require('./multipart'), auth = require('./auth'), @@ -106,7 +106,8 @@ var defaults = { follow_keep_method : false, follow_if_same_host : false, follow_if_same_protocol : false, - follow_if_same_location : false + follow_if_same_location : false, + use_proxy_from_env_var : true } var aliased = { @@ -255,12 +256,14 @@ Needle.prototype.setup = function(uri, options) { } } - var env_proxy = utils.get_env_var(['HTTP_PROXY', 'HTTPS_PROXY'], true); - if (!config.proxy && env_proxy) config.proxy = env_proxy; + if (config.use_proxy_from_env_var) { + var env_proxy = utils.get_env_var(['HTTP_PROXY', 'HTTPS_PROXY'], true); + if (!config.proxy && env_proxy) config.proxy = env_proxy; + } // if proxy is present, set auth header from either url or proxy_user option. if (config.proxy) { - if (utils.should_proxy_to(uri)) { + if (!config.use_proxy_from_env_var || utils.should_proxy_to(uri)) { if (config.proxy.indexOf('http') === -1) config.proxy = 'http://' + config.proxy; diff --git a/package-lock.json b/package-lock.json index d19d745c6..807df82fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,14 +48,6 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, - "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "requires": { - "ms": "^2.1.1" - } - }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", diff --git a/package.json b/package.json index 3303c264a..0e2b5da8d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "url": "https://github.com/tomas/needle.git" }, "dependencies": { - "debug": "^3.2.6", "iconv-lite": "^0.6.3", "sax": "^1.2.4" }, diff --git a/test/proxy_spec.js b/test/proxy_spec.js index b85d6185a..46b0b5ec3 100644 --- a/test/proxy_spec.js +++ b/test/proxy_spec.js @@ -228,4 +228,41 @@ describe('proxy option', function() { }) + describe('when environment variable is set', function() { + + describe('and default is unchanged', function() { + + before(function() { + process.env.HTTP_PROXY = 'foobar'; + }) + + after(function() { + delete process.env.HTTP_PROXY; + }) + + it('tries to proxy', function(done) { + send_request({}, proxied('foobar', 80, done)) + }) + + }) + + describe('and functionality is disabled', function() { + + before(function() { + process.env.HTTP_PROXY = 'foobar'; + }) + + after(function() { + delete process.env.HTTP_PROXY; + }) + + it('ignores proxy', function(done) { + send_request({ + use_proxy_from_env_var: false + }, not_proxied(done)) + }) + + }) + }) + })