-
-
Notifications
You must be signed in to change notification settings - Fork 957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WHATWG URL support #289
Conversation
I think this is the correct approach. We just want to support WHATWG URLs now, not use them internally. Can you also document this? |
package.json
Outdated
@@ -48,6 +48,7 @@ | |||
"is-redirect": "^1.0.0", | |||
"is-retry-allowed": "^1.0.0", | |||
"is-stream": "^1.0.0", | |||
"isurl": "^1.0.0-alpha3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's 1.0.0-alpha5
now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one doesn't work 😓 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isURL.lenient(url)
package.json
Outdated
@@ -64,6 +65,7 @@ | |||
"pem": "^1.4.4", | |||
"pify": "^2.3.0", | |||
"tempfile": "^1.1.1", | |||
"whatwg-url": "^4.6.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And ^4.7.1
dcb8677
to
28fe6d3
Compare
@stevenvachon Can you review? |
@alextes Tests are failing |
test/arguments.js
Outdated
@@ -1,3 +1,4 @@ | |||
import {URL} from 'whatwg-url'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be more complete to use universal-url here so that the Node v7 URL
is included in tests when available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. It'd be nice to test both the native and shim. I'm swapping it out. Just to make sure, how does the rest feel about going from a lib that's seen tons of use to something that's still in alpha?
index.js
Outdated
@@ -206,6 +207,10 @@ function normalizeArguments(url, opts) { | |||
} | |||
} | |||
|
|||
if (isURL(url)) { | |||
url = urlParseLax(url.href); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no auth (username
,password
) check in this block like there is for string input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, reparsing the url is not the best idea for performance.
readme.md
Outdated
@@ -62,7 +62,7 @@ Returns a Promise for a `response` object with a `body` property, a `url` proper | |||
|
|||
Type: `string`, `object` | |||
|
|||
The URL to request or a [`http.request` options](https://nodejs.org/api/http.html#http_http_request_options_callback) object. | |||
The URL to request as simple string, a [`http.request` options](https://nodejs.org/api/http.html#http_http_request_options_callback), or a [`WHATWG-URL`](https://nodejs.org/api/url.html#url_class_url). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more accurate:
, or a WHATWG
URL
.
Thanks for the feedback! Will update tomorrow 😄. |
@sindresorhus @stevenvachon ready for review 😁! |
package.json
Outdated
@@ -69,6 +70,8 @@ | |||
"nyc": "^10.0.0", | |||
"pem": "^1.4.4", | |||
"pify": "^2.3.0", | |||
"universal-url": "^1.0.0-alpha", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetical order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry 😅. It was late.
So I've gotten stuck implementing this.
The way I imagine things, this PR is a bad idea or I've been way overthinking the whole time. With this PR the nuances between the way Node handles a Node urlObject or whatwg urlObject would be lost. I tried to dig into the Node v8 nightly to confirm but couldn't find anything. I assumed this can't be done because this PR trivially supports whatwg-urls on any Node and I thought that wasn't possible.
The second suggestion was keeping the URL object intact and supporting whatwg-url on Node >= v8. This makes less sense the more I think about it. Some issues I can think of:
http.request
options, which we use to overwrite the URL object.http.request
options that are not Node URL properties? If you have to serialize the whatwg-url in order to do that what's the point keeping it intact in the first place? The current Node implementation runs it through url.parse anyway. If that is going to stay the same in v8, this PR seems like an adequate solution.I guess the core question I'm asking is: does it matter if you serialize a whatwg-url then parse it with node's url.parse or directly pass it to node? I can't tell from skimming the whatwg-url spec.
Note to self: if we're going with normalizing whatwg-url's take care of sneaking in auth.
Sidenote to self: dealing with features supported in some versions of Node is tricky 😓.
Fixes #228