Thursday, 11 May 2017

How to disable certificate caching in https.get call of node.js?

I have following node.js code to get the certificates and other details of the server. But it's getting the certificate only in the first call of https.get. Successive calls are not fetching the certificates from the server.

var https = require('https');
var i = 0;
test();

function test() {
    var request = https.get("https://google.com", function (result) {
        console.log(result.statusCode)
        var cert = result.connection.getPeerCertificate(true);
        console.log("Certificate is", cert)
        i++;
        if (i < 10)
            test();
    }).on('error', function (err) {
        console.log("error is", err);
    })
}

So I feel Node.js will cache the server certificate received.

If that's the case, then how can I clear the certificates present in the memory.

If not, then what is the reason for this issue?



via Santosh Hegde

No comments:

Post a Comment