sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Unnecessary deprecation warning when use https options and retry in afterResponse hook #1389

Closed fleg closed 4 years ago

fleg commented 4 years ago

Describe the bug

I'm trying to use https options (for example https.certificateAuthority) and afterResponse hook with retry. On retried request got prints DeprecationWarning: (node:10192) DeprecationWarning: Got: "options.ca" was never documented, please use "options.https.certificateAuthority", but I do not use options.ca. Same with other https options: certificate, key and passphrase.

Actual behavior

Terminal output:

retry
(node:10192) DeprecationWarning: Got: "options.ca" was never documented, please use "options.https.certificateAuthority"
{"hello":"world"}

Expected behavior

Terminal output:

retry
{"hello":"world"}

Code to reproduce

const got = require('got');

// amazon ca
const certificateAuthority =
`-----BEGIN CERTIFICATE-----
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL
MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv
b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj
ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM
9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw
IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6
VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L
93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm
jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA
A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI
U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs
N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv
o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU
5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy
rqXRfboQnoZsG4q5WTP468SQvvG5
-----END CERTIFICATE-----`;

(async () => {
    let shouldRetry = true;
    const {body} = await got.post('https://httpbin.org/anything', {
        json: {hello: 'world'},
        responseType: 'json',
        https: {certificateAuthority},
        hooks: {
            afterResponse: [
                (response, retry) => {
                    if (shouldRetry) {
                        shouldRetry = false;
                        console.log('retry');

                        return retry();
                    }

                    return response;
                }
            ]
        }
    });

    console.log(body.data);
})().catch(console.error);

PR with failing test: https://github.com/sindresorhus/got/pull/1390

Checklist

szmarczak commented 4 years ago

/cc @Giotino

Giotino commented 4 years ago

My bad, I forgot to restore the options as they where before the request. Working on it.