Skip to content

Commit

Permalink
Deep merge of https options (sindresorhus#1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giotino authored and szmarczak committed Jul 6, 2020
1 parent d73216b commit cf89d30
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}

// HTTPS options
if (defaults?.https) {
options.https = {...defaults.https, ...options.https};
}

if ('rejectUnauthorized' in options) {
deprecationWarning('"options.rejectUnauthorized" is now deprecated, please use "options.https.rejectUnauthorized"');
}
Expand Down
30 changes: 30 additions & 0 deletions test/merge-instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,33 @@ test('URL is not polluted', withServer, async (t, server, got) => {

t.is(normalizedOptions.username, '');
});

test('merging instances with HTTPS options', t => {
const instanceA = got.extend({https: {
rejectUnauthorized: true,
certificate: 'FIRST'
}});
const instanceB = got.extend({https: {
certificate: 'SECOND'
}});

const merged = instanceA.extend(instanceB);

t.true(merged.defaults.options.https?.rejectUnauthorized);
t.is(merged.defaults.options.https?.certificate, 'SECOND');
});

test('merging instances with HTTPS options undefined', t => {
const instanceA = got.extend({https: {
rejectUnauthorized: true,
certificate: 'FIRST'
}});
const instanceB = got.extend({https: {
certificate: undefined
}});

const merged = instanceA.extend(instanceB);

t.true(merged.defaults.options.https?.rejectUnauthorized);
t.is(merged.defaults.options.https?.certificate, undefined);
});

0 comments on commit cf89d30

Please sign in to comment.