Skip to content

Commit

Permalink
Fixed deprecationWarning on https options (#1391)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksey Timchenko <[email protected]>
  • Loading branch information
Giotino and fleg authored Aug 6, 2020
1 parent a748343 commit 9a309bd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,33 @@ export default class Request extends Duplex implements RequestEvents<Request> {
options.timeout = timeout;
options.agent = agent;

// HTTPS options restore
if (options.https) {
if ('rejectUnauthorized' in options.https) {
delete requestOptions.rejectUnauthorized;
}

if (options.https.checkServerIdentity) {
delete requestOptions.checkServerIdentity;
}

if (options.https.certificateAuthority) {
delete requestOptions.ca;
}

if (options.https.certificate) {
delete requestOptions.cert;
}

if (options.https.key) {
delete requestOptions.key;
}

if (options.https.passphrase) {
delete requestOptions.passphrase;
}
}

if (isClientRequest(requestOrResponse)) {
this._onRequest(requestOrResponse);

Expand Down
42 changes: 42 additions & 0 deletions test/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,48 @@ test('https request with ca', withServer, async (t, server, got) => {
t.is(body, 'ok');
});

test('https request with ca and afterResponse hook', withServer, async (t, server, got) => {
server.get('/', (_request, response) => {
response.end('ok');
});

const warningListener = (warning: any) => {
if (
warning.name === 'DeprecationWarning' &&
warning.message === 'Got: "options.ca" was never documented, please use ' +
'"options.https.certificateAuthority"'
) {
process.off('warning', warningListener);
t.fail('unexpected deprecation warning');
}
};

process.once('warning', warningListener);

let shouldRetry = true;
const {body} = await got.secure({
https: {
certificateAuthority: server.caCert
},
headers: {host: 'example.com'},
hooks: {
afterResponse: [
(response, retry) => {
if (shouldRetry) {
shouldRetry = false;

return retry({});
}

return response;
}
]
}
});

t.is(body, 'ok');
});

test('https request with `checkServerIdentity` OK', withServer, async (t, server, got) => {
server.get('/', (_request, response) => {
response.end('ok');
Expand Down

0 comments on commit 9a309bd

Please sign in to comment.