Skip to content

Commit

Permalink
feat: support subdomain matching via leading dot in no_proxy rule
Browse files Browse the repository at this point in the history
Support subdomain matching via leading dot in no_proxy rule
  • Loading branch information
gajus authored Jun 27, 2019
2 parents f17386d + 2eaf2eb commit d727a23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/utilities/isUrlMatchingNoProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default (subjectUrl: string, noProxy: string) => {
const rules = noProxy.split(/[,\s]/);

for (const rule of rules) {
const ruleMatch = rule.match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
const ruleMatch = rule
.replace(/^(?<leadingDot>\.)/, '*')
.match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);

if (!ruleMatch || !ruleMatch.groups) {
throw new UnexpectedStateError('Invalid NO_PROXY pattern.');
Expand Down
14 changes: 13 additions & 1 deletion test/global-agent/utilities/isUrlMatchingNoProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ test('returns `true` if hosts match (IP)', (t) => {
t.assert(isUrlMatchingNoProxy('http://127.0.0.1/', '127.0.0.1'));
});

test('returns `true` if hosts match (using wildcard)', (t) => {
test('returns `true` if hosts match (using asterisk wildcard)', (t) => {
t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '*.foo.com'));
});

test('returns `true` if domain matches (using dot wildcard)', (t) => {
t.assert(isUrlMatchingNoProxy('http://foo.com/', '.foo.com'));
});

test('returns `true` if subdomain matches (using dot wildcard)', (t) => {
t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '.foo.com'));
});

test('returns `true` if hosts match (*) and ports match', (t) => {
t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', '*:8080'));
});
Expand Down Expand Up @@ -42,3 +50,7 @@ test('returns `false` if hosts match and ports do not match (port not present su
test('returns `true` if hosts match and ports do not match (port not present NO_PROXY)', (t) => {
t.assert(isUrlMatchingNoProxy('http://foo.com:8000/', 'foo.com'));
});

test('returns `true` if hosts match in one of multiple rules', (t) => {
t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org,foo.com,baz.io'));
});

0 comments on commit d727a23

Please sign in to comment.