interceptors icon indicating copy to clipboard operation
interceptors copied to clipboard

Fix Node.js url options parsing

Open mikicho opened this issue 1 year ago • 0 comments

Following of this comment, I revisited the options parsing rules according to Node.js source and docs, and a few insights:

  1. host and hostname are the same, hostname is preferred if both are specified.
  2. host (and hostname) is Domain Name and doesn't include the port.
  3. Node doesn't parse the port from the host. if a user includes the port in the host, Node refers to it as part of the host, and the result is an invalid URL like: http://google.com:1234:80

I also added tests for ipv6. Last, the current implementation only differs from Node.js in that we return an Invalid URL instead of firing a bad request. This is due to the fact that we convert options to URL first. However, I believe this behavior is acceptable.

should fix #451

mikicho avatar Nov 28 '23 21:11 mikicho