Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WHATWG URL support #289

Merged
merged 9 commits into from
May 15, 2017
Merged

Conversation

alextes
Copy link
Contributor

@alextes alextes commented Mar 26, 2017

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:

  • Any place you read from or write to the URL you'd have to be aware of which type you're dealing with. (If you normalize you're effectively doing what this PR is)
  • We currently support all of the http.request options, which we use to overwrite the URL object.
  • How does one pass node's 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

@alextes alextes changed the title Add WHATWG-URL support Add WHATWG-URL support (needs feedback) Mar 31, 2017
@alextes alextes changed the title Add WHATWG-URL support (needs feedback) Add WHATWG-URL support Apr 24, 2017
@sindresorhus
Copy link
Owner

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",
Copy link
Owner

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

Copy link
Contributor Author

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 馃槗 .

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And ^4.7.1

@alextes alextes force-pushed the whatwg-url branch 2 times, most recently from dcb8677 to 28fe6d3 Compare May 4, 2017 01:25
@sindresorhus
Copy link
Owner

@stevenvachon Can you review?

@sindresorhus
Copy link
Owner

@alextes Tests are failing

@@ -1,3 +1,4 @@
import {URL} from 'whatwg-url';
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor

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).
Copy link
Contributor

@stevenvachon stevenvachon May 4, 2017

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.

@alextes
Copy link
Contributor Author

alextes commented May 4, 2017

Thanks for the feedback! Will update tomorrow 馃槃.

@alextes
Copy link
Contributor Author

alextes commented May 13, 2017

@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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetical order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry 馃槄. It was late.

@sindresorhus sindresorhus changed the title Add WHATWG-URL support Add WHATWG URL support May 15, 2017
@sindresorhus sindresorhus merged commit f501fc2 into sindresorhus:master May 15, 2017
@alextes alextes deleted the whatwg-url branch May 15, 2017 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants