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.

32 lines
524 B

4 years ago
  1. "use strict";
  2. function parsePort(urlObj, options)
  3. {
  4. var defaultPort = -1;
  5. for (var i in options.defaultPorts)
  6. {
  7. if ( i===urlObj.scheme && options.defaultPorts.hasOwnProperty(i) )
  8. {
  9. defaultPort = options.defaultPorts[i];
  10. break;
  11. }
  12. }
  13. if (defaultPort > -1)
  14. {
  15. // Force same type as urlObj.port
  16. defaultPort = defaultPort.toString();
  17. if (urlObj.port === null)
  18. {
  19. urlObj.port = defaultPort;
  20. }
  21. urlObj.extra.portIsDefault = (urlObj.port === defaultPort);
  22. }
  23. }
  24. module.exports = parsePort;