-
-
Notifications
You must be signed in to change notification settings - Fork 959
Merging port
into defaults doesn't work with prefixUrl
#1668
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
Comments
|
|
How do you figure?
Which includes got("http://localhost", {
port: 8000,
timeout: 100,
})
.catch(reason => {
console.log(reason.message)
})
//=> "connect ECONNREFUSED 127.0.0.1:8000"
Thanks for the suggestion. If you're saying that And aside from the ergonomics, that appears to result in internal inconsistency: const gotInstance = got.extend({
mutableDefaults: true,
prefixUrl: "http://example.com:8888",
})
gotInstance.defaults.options = gotInstance.mergeOptions(gotInstance.defaults.options, {
prefixUrl: "http://example.com:9999",
})
console.log(gotInstance.defaults.options.prefixUrl)
console.log(gotInstance.defaults.options.url)
What does the hooks.init documentation mean by?:
Why / when would the options object have a On a side matter, why make updating the defaults so ceremonious? // Before
gotInstance.defaults.options = got.mergeOptions(gotInstance.defaults.options, options)
// After
gotInstance.mergeInOptions(options) |
The docs are a bit outdated. Passing
See my comment above.
Options will be a lot stricter in Got 12 - will throw when setting a non-existing option. Each option will be documented properly and the merging behavior will also be documented.
The const got = require('got')
const gotInstance = got.extend({
mutableDefaults: true,
prefixUrl: "http://example.com:8888",
})
gotInstance.defaults.options = gotInstance.mergeOptions(gotInstance.defaults.options, {
prefixUrl: "http://example.com:9999",
})
gotInstance('', {timeout: 0}).catch(error => console.log(error.options.url.toString()));
console.log(gotInstance.defaults.options.prefixUrl)
console.log(gotInstance.defaults.options.url.toString())
See https://github.com/sindresorhus/got#hooksbeforeredirect - but the example is outdated. It should access
You might want to reuse merged options for performance reasons. This will be documented in Got 12. |
It means that if you need to replace some part of the URL every time, then you need to use |
That's good to know, but again, this is about the released version, 11.8.2. It comes across as dismissive when you close an issue on the basis that {x} isn't an option when {x} is documented (and utilized!) as an option by the version of the package in question.
👍 That's great! I appreciate the attention to the documentation.
Ok, thank you.
So if I pass
Ok thanks.
Ok thanks. It'll be good to see that documentation, because I'm not sure what scenario you're describing. It seems like most of the time a method like
Yeah my question was about the reference to...
...because I don't see that property documented. So if not for that reference I would have no reason to expect that the options object would ever have a |
Yes.
This seems like a good idea but note that it would be
Well, Got 12 is going to have an |
Actually I tried const got = require('got');
const gotInstance = got.extend({
mutableDefaults: true,
prefixUrl: "http://example.com:8888",
});
// gotInstance.defaults.options.url = undefined;
const parsedPrefixUrl = new URL(gotInstance.defaults.options.prefixUrl);
parsedPrefixUrl.port = 9999;
// Got 11
gotInstance.defaults.options.prefixUrl = parsedPrefixUrl.href; and it turns out that it's not possible because |
You're right, this should've been properly documented. Got 12 is going to feature a much better documentation. |
Ok thanks.
I actually wanted to ask if it's supposed to be supported (I'm talking about v11 here) to set properties of /* 1A) */
const gotInstance = got.extend({
mutableDefaults: true,
prefixUrl: "http://example.com",
})
gotInstance.defaults.options = gotInstance.mergeOptions(gotInstance.defaults.options, {
prefixUrl: "http://example.com:9999",
})
gotInstance("", {timeout: 0}).catch(reason => {
console.log("", reason.options.url.toString())
})
//=> http://example.com:9999/
/* ... */
/* 1B) */
const gotInstance = got.extend({
mutableDefaults: true,
prefixUrl: "http://example.com",
})
gotInstance.defaults.options.prefixUrl = "http://example.com:9999"
//=> Error: Cannot change `prefixUrl` from http://example.com/ to http://example.com:9999: http://example.com/ /* 2A) */
const gotInstance = got.extend({
mutableDefaults: true,
prefixUrl: "http://example.com",
})
gotInstance.defaults.options = gotInstance.mergeOptions(gotInstance.defaults.options, {
port: 9999,
})
gotInstance("", {timeout: 0}).catch(reason => {
console.log("", reason.options.url.toString())
})
//=> http://example.com/
/* ... */
/* 2B) */
const gotInstance = got.extend({
mutableDefaults: true,
prefixUrl: "http://example.com",
})
gotInstance.defaults.options.port = 9999
gotInstance("", {timeout: 0}).catch(reason => {
console.log("", reason.options.url.toString())
})
//=> http://example.com:9999/
Ok thanks. For my present use case I think I'm just going to defer setting But in the bigger picture, as we're both seeing and these examples show, the behavior is inconsistent / surprising / not intuitive right now. Maybe I'm not thinking of all the angles, but I wonder if it wouldn't be simpler to just base the whole thing on a
...and
Ok thanks, 🙌 for the docs. |
This has been already discussed and we decided to go with |
It should be possible to do both, but |
Describe the bug
With Node 12, [email protected].
Merging
port
into default options doesn't work whenprefixUrl
is set.Code to reproduce
See https://github.com/jmm/repro-got-merge-port-to-defaults.
Actual behavior
I expect port to be set as specified and the assertion to be true.
Expected behavior
Port is undefined.
I suspect this code: https://github.com/sindresorhus/got/blob/v11.8.2/source/core/index.ts#L1639-L1645
The text was updated successfully, but these errors were encountered: