Skip to content

Commit

Permalink
Merge branch 'master' into HAL
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas authored Dec 8, 2023
2 parents be72f5c + d3ec179 commit 4b6503e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
13 changes: 8 additions & 5 deletions lib/needle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
37 changes: 37 additions & 0 deletions test/proxy_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

})
})

})

0 comments on commit 4b6503e

Please sign in to comment.