Node: Multi-hosts urls

Created on 29 Jun 2018  路  3Comments  路  Source: nodejs/node

url.parse and URL (it just throws) don't handle urls with multiple hosts

var u = url.parse('mongodb://server1.db.foo.net:27017,server2.db.foo.net:27017,server3.db.foo.net:27017/data?authMechanism=MONGO-X509&replicaSet=rs0&ssl=true&sslValidate=true', true)
/*
Url {
  protocol: 'https:',
  slashes: true,
  auth: 'foo',
  host: 'server1.foo.net:7998',
  port: '7998',
  hostname: 'server1.foo.net',
  hash: null,
  search:
   '?authMechanism=X509&replicaSet=rs0&ssl=true&sslValidate=true',
  query:
   { authMechanism: 'X509',
     replicaSet: 'rs0',
     ssl: 'true',
     sslValidate: 'true' },
  pathname: '/:7998,server2.foo.net:7998,server3.foo.net/data',
  path:
   '/:7998,server2.foo.net:7998,server3.foo.net/data?authMechanism=X509&replicaSet=rs0&ssl=true&sslValidate=true',
// ...
*/

python can handle them: https://github.com/whatwg/url/issues/398#issuecomment-401348316

So I wonder if it couldn't be something we can change in node?

feature request url whatwg-url

Most helpful comment

Given that this is not standard URL syntax (for both IETF and WHATWG specs)... this is not a syntax Node.js likely to support natively. At this point, the older url.parse() is legacy and not likely to be significantly updated and the WHATWG URL implementation is guided by the WHATWG specification in order to maintain compatibility.

For Node.js, the best bet for this would be implementation of a userland module that handles these.

All 3 comments

Given that this is not standard URL syntax (for both IETF and WHATWG specs)... this is not a syntax Node.js likely to support natively. At this point, the older url.parse() is legacy and not likely to be significantly updated and the WHATWG URL implementation is guided by the WHATWG specification in order to maintain compatibility.

For Node.js, the best bet for this would be implementation of a userland module that handles these.

I think this isn't something Node should take up, thought it might be something https://url.spec.whatwg.org/ could be amended to support.

Closing given the response

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Icemic picture Icemic  路  3Comments

dfahlander picture dfahlander  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

willnwhite picture willnwhite  路  3Comments

akdor1154 picture akdor1154  路  3Comments