mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
535 stars 120 forks source link

fix: support IPv6 during ClientRequest options parsing #489

Closed mikicho closed 4 months ago

mikicho commented 9 months ago

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

kettanaito commented 4 months ago

Released: v0.29.0 🎉

This has been released in v0.29.0!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.