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

Replace baseUrl with prefixUrl #829

Merged
merged 9 commits into from Sep 4, 2019

Conversation

szmarczak
Copy link
Collaborator

@szmarczak szmarczak commented Jul 11, 2019

Checklist

  • I have read the documentation.
  • I have included a pull request description of my changes.
  • I have included some tests.
  • If it's a new feature, I have included documentation updates.

Fixes #783
Fixes #814

readme.md Outdated Show resolved Hide resolved
@@ -83,6 +81,7 @@ To use streams, just call `got.stream(url, options)` or `got(url, {stream: true,
- No `forever` option. You need to use [forever-agent](https://github.com/request/forever-agent).
- No `proxy` option. You need to [pass a custom agent](readme.md#proxies).
- No `removeRefererHeader` option. You can remove the referer header in a [`beforeRequest` hook](https://github.com/sindresorhus/got#hooksbeforeRequest):
- No `baseUrl` option. Instead, there is `prefixUrl` which appends ending slash if not present.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
- No `baseUrl` option. Instead, there is `prefixUrl` which appends ending slash if not present.
- No `baseUrl` option. Instead, there is `prefixUrl` which appends ending slash if not present. If `prefixUrl` is used, it will be always prepended to the `url` argument.

Actually should we do

if (options.prefixUrl && !urlArgument.startsWith('http:') && !urlArgument.startsWith('https:') && !urlArgument.startsWith('unix:')) {
    ...
}

or let this behavior be?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

My opinion has always been that input should not be able to override the host of a prefixUrl, otherwise it's not really a prefix. If such an override is needed, and it very well may be for some use cases, then I feel that full URL resolution is the answer (I.e. baseUrl). I don't think we have any business keeping a list of "special" schemes like http: where absolute URLs can override the target host. That is the job of a URL resolver, and I'd prefer to either fully embrace URL resolution or not at all.

I'm personally fine with having both prefixUrl and baseUrl. But I know Sindre felt that would be confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What if we pass a URL instance to input? I think we should ignore prefixUrl then (same for Ky).

Choose a reason for hiding this comment

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

Why does a URL instance change the behavior as opposed to a string? I would expect them to behave the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The URL instance is an absolute URL. Is there any use case for joining two absolute URLs? The string does not need to be absolute. That's the difference.

Choose a reason for hiding this comment

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

Oh, right. I forgot that URL instances are always absolute, because that's such a silly limitation in the URL class. So, yeah, if absolute URLs are allowed to override prefixUrl, then it makes sense. However, in terms of the code, I would probably not explicitly check for URL instances, if possible. After all, what if URL starts supporting relative URLs in the future? I think they could introduce support for that without breaking too many things. And I hope they do, personally.

Copy link
Owner

Choose a reason for hiding this comment

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

My opinion has always been that input should not be able to override the host of a prefixUrl

👍 (We can reconsider if we get a lot of complain about this)

@szmarczak szmarczak added the breaking API changes / behavior changes label Jul 11, 2019
advanced-creation.md Show resolved Hide resolved
migration-guides.md Outdated Show resolved Hide resolved
test/cache.ts Outdated Show resolved Hide resolved
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
@sindresorhus
Copy link
Owner

There are still some references to baseUrl:

readme.md
715:	baseUrl: 'https://example.com',
733:		baseUrl: 'httpbin.org',
1024:	baseUrl: 'https://<api-id>.execute-api.<api-region>.amazonaws.com/<stage>/',
1149:Use `got.extend()` to make it nicer to work with REST APIs. Especially if you use the `baseUrl` option.
1158:	baseUrl: 'example.com',

@sindresorhus
Copy link
Owner

There are still some references to baseUrl:

Fixed

@sindresorhus sindresorhus merged commit 0d534ed into sindresorhus:master Sep 4, 2019
@sindresorhus
Copy link
Owner

Nice work! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking API changes / behavior changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

got.extend doesn't support "unix:" protocol Ambiguous URLs
3 participants