Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
fix(agent): check uppercase & lowercase proxy env (#24)
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
Alexander Plavinski authored and zkat committed Apr 24, 2017
1 parent f710049 commit acf2326
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
31 changes: 27 additions & 4 deletions agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,38 @@ function checkNoProxy (uri) {
return false
}

module.exports.getProcessEnv = getProcessEnv

function getProcessEnv (env) {
if (!env) { return }

let value

if (Array.isArray(env)) {
for (let e of env) {
value = process.env[e] ||
process.env[e.toUpperCase()] ||
process.env[e.toLowerCase()]
if (typeof value !== 'undefined') { break }
}
}

if (typeof env === 'string') {
value = process.env[env] ||
process.env[env.toUpperCase()] ||
process.env[env.toLowerCase()]
}

return value
}

function getProxyUri (uri, opts) {
const protocol = url.parse(uri).protocol

const proxy = opts.proxy || (
protocol === 'https:' && process.env.https_proxy
protocol === 'https:' && getProcessEnv('https_proxy')
) || (
protocol === 'http:' && (
process.env.https_proxy || process.env.http_proxy || process.env.proxy
)
protocol === 'http:' && getProcessEnv(['https_proxy', 'http_proxy', 'proxy'])
)

const parsedProxy = (typeof proxy === 'string') ? url.parse(proxy) : proxy
Expand Down
17 changes: 17 additions & 0 deletions test/agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const test = require('tap').test
const getProcessEnv = require('../agent').getProcessEnv

test('extracts process env variables', t => {
process.env = { TEST_ENV: 'test', ANOTHER_ENV: 'no' }

t.deepEqual(getProcessEnv('test_ENV'), 'test', 'extracts single env')

t.deepEqual(
getProcessEnv(['not_existing_env', 'test_ENV', 'another_env']),
'test',
'extracts env from array of env names'
)
t.done()
})

0 comments on commit acf2326

Please sign in to comment.