Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

isUrlMatchingNoProxy.js.flow 1022B

12345678910111213141516171819202122232425262728293031323334353637
  1. // @flow
  2. import {
  3. parse as parseUrl,
  4. } from 'url';
  5. import matcher from 'matcher';
  6. import {
  7. UnexpectedStateError,
  8. } from '../errors';
  9. export default (subjectUrl: string, noProxy: string) => {
  10. const subjectUrlTokens = parseUrl(subjectUrl);
  11. const rules = noProxy.split(/[\s,]+/);
  12. for (const rule of rules) {
  13. const ruleMatch = rule
  14. .replace(/^(?<leadingDot>\.)/, '*')
  15. .match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
  16. if (!ruleMatch || !ruleMatch.groups) {
  17. throw new UnexpectedStateError('Invalid NO_PROXY pattern.');
  18. }
  19. if (!ruleMatch.groups.hostname) {
  20. throw new UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
  21. }
  22. const hostnameIsMatch = matcher.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
  23. if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
  24. return true;
  25. }
  26. }
  27. return false;
  28. };