summaryrefslogtreecommitdiff
path: root/node_modules/global-agent/src/utilities/isUrlMatchingNoProxy.js
diff options
context:
space:
mode:
authorLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
committerLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
commit703e03aba33f234712206769f57717ba7d92d23d (patch)
tree0041f04ccb75bd5379c764e9fe42249fffe75fc3 /node_modules/global-agent/src/utilities/isUrlMatchingNoProxy.js
parentab6e257e6e9d9a483d7e86f220d8b209a2cd7753 (diff)
downloadFlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.gz
FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.zst
Added export_allowed file to make repository visible in cgit
Diffstat (limited to 'node_modules/global-agent/src/utilities/isUrlMatchingNoProxy.js')
-rw-r--r--node_modules/global-agent/src/utilities/isUrlMatchingNoProxy.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/node_modules/global-agent/src/utilities/isUrlMatchingNoProxy.js b/node_modules/global-agent/src/utilities/isUrlMatchingNoProxy.js
new file mode 100644
index 0000000..f2de584
--- /dev/null
+++ b/node_modules/global-agent/src/utilities/isUrlMatchingNoProxy.js
@@ -0,0 +1,37 @@
+// @flow
+
+import {
+ parse as parseUrl,
+} from 'url';
+import matcher from 'matcher';
+import {
+ UnexpectedStateError,
+} from '../errors';
+
+export default (subjectUrl: string, noProxy: string) => {
+ const subjectUrlTokens = parseUrl(subjectUrl);
+
+ const rules = noProxy.split(/[\s,]+/);
+
+ for (const rule of rules) {
+ const ruleMatch = rule
+ .replace(/^(?<leadingDot>\.)/, '*')
+ .match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
+
+ if (!ruleMatch || !ruleMatch.groups) {
+ throw new UnexpectedStateError('Invalid NO_PROXY pattern.');
+ }
+
+ if (!ruleMatch.groups.hostname) {
+ throw new UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
+ }
+
+ const hostnameIsMatch = matcher.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
+
+ if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
+ return true;
+ }
+ }
+
+ return false;
+};