Skip to content

Commit

Permalink
Won't use HTTP(S)_PROXY env var if proxy explicitly set to null.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmccarthy committed Apr 3, 2014
1 parent 8a0e2d6 commit e86377c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Request.prototype.init = function (options) {
self.rejectUnauthorized = false
}

if(!self.proxy) {
if(!self.hasOwnProperty('proxy')) {
// check for HTTP(S)_PROXY environment variables
if(self.uri.protocol == "http:") {
self.proxy = process.env.HTTP_PROXY || process.env.http_proxy || null;
Expand Down
39 changes: 39 additions & 0 deletions tests/test-proxy-null.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var server = require('./server')
, events = require('events')
, stream = require('stream')
, assert = require('assert')
, fs = require('fs')
, request = require('../index')
, path = require('path')
, util = require('util')
;

var port = 6768
, called = false
, proxiedHost = 'google.com'
;

// set up environment variable
process.env.HTTP_PROXY = 'http://localhost:'+port;

var s = server.createServer(port)
s.listen(port, function () {
s.on('http://google.com/', function (req, res) {
called = true
assert.equal(req.headers.host, proxiedHost)
res.writeHeader(200)
res.end()
})
request ({
url: 'http://'+proxiedHost,
// should not read from HTTP_PROXY env var
proxy: null,
timeout: 500,
}, function (err, res, body) {
s.close()
})
})

process.on('exit', function () {
assert.ok(!called, 'the request must not be made to the proxy server')
})

0 comments on commit e86377c

Please sign in to comment.