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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove require('url') in favor of URL #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

remove require('url') in favor of URL #55

wants to merge 3 commits into from

Conversation

Flet
Copy link
Collaborator

@Flet Flet commented Oct 29, 2019

Closes #53

This also updates travis to use node versions 12 and 10 for tests.

node 8.x is at EOL starting December 2019.

@feross
Copy link
Owner

feross commented Nov 5, 2019

Could you explain a bit more about the changes, like why you were able to remove the different code paths for relative/absolute URLs, and why you're now passing href in the opts object. Thanks!

@LinusU
Copy link
Collaborator

LinusU commented Feb 6, 2022

I wanted to land this so rebased on master. Unfortunately, this was harder than I thought!

Since the current API allows passing any different combinations of options that is being feed right into http.request it's very hard to keep the current API whilst moving to using URL. I added two failing test cases that demonstrates two of the shortcomings.

I'm thinking that the best way forward is a new major release which explicitly states which options are valid, and only allows the new WHATWG URL based ones:

Potentially also switching url for href:


For reference, here is the code to turn Node.js style opts into an url string, which we would need in order to pass it to as the base parameter to new URL:

https://github.com/nodejs/node/blob/4712472c0fa1fbd7df74541698659b85313ab576/lib/url.js#L614-L698

Here is a util function that turns an URL into the expected request options, not too complicated:

https://github.com/nodejs/node/blob/30bdee20ee3a24fa12958c7fad51d9b174c765ad/lib/internal/url.js#L1395-L1418


edit: Hmm, I actually manage to get a version with every test passing, but there is a lot of code added in order for this, which I think that we should avoid...

You can see it here: https://github.com/feross/simple-get/compare/url-linusu-wip

The out-commented setOptionsFromUrl is needed in order to support Node.js 10.0.0 - 10.8.0 😅

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.

Remove require('url') in favor of URL
3 participants