Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
56 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
function formatHostname (hostname) { | ||
// canonicalize the hostname, so that 'oogle.com' won't match 'google.com' | ||
return hostname.replace(/^\.*/, '.').toLowerCase() | ||
} | ||
|
||
function parseNoProxyZone (zone) { | ||
zone = zone.trim().toLowerCase() | ||
|
||
var zoneParts = zone.split(':', 2) | ||
var zoneHost = formatHostname(zoneParts[0]) | ||
var zonePort = zoneParts[1] | ||
var hasPort = zone.indexOf(':') > -1 | ||
|
||
return {hostname: zoneHost, port: zonePort, hasPort: hasPort} | ||
} | ||
|
||
function uriInNoProxy (uri, noProxy) { | ||
var port = uri.port || (uri.protocol === 'https:' ? '443' : '80') | ||
var hostname = formatHostname(uri.hostname) | ||
var noProxyList = noProxy.split(',') | ||
|
||
// iterate through the noProxyList until it finds a match. | ||
return noProxyList.map(parseNoProxyZone).some(function (noProxyZone) { | ||
var isMatchedAt = hostname.indexOf(noProxyZone.hostname) | ||
var hostnameMatched = ( | ||
isMatchedAt > -1 && | ||
(isMatchedAt === hostname.length - noProxyZone.hostname.length) | ||
) | ||
|
||
if (noProxyZone.hasPort) { | ||
return (port === noProxyZone.port) && hostnameMatched | ||
} | ||
|
||
return hostnameMatched | ||
}) | ||
} | ||
|
||
module.exports = uriInNoProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters