Skip to content
Discussion options

You must be logged in to vote

You can access the TLS certificate through response.socket, but there are some caveats:

import got from 'got';

const response = await got('https://example.com');

// Access certificate info
if (response.socket && response.socket.getPeerCertificate) {
	const cert = response.socket.getPeerCertificate();
	const protocol = response.socket.getProtocol();
	const valid = response.socket.authorized;
	const error = response.socket.authorizationError;
	
	console.log(cert, protocol, valid, error);
}

Important caveats:

  1. Connection reuse: With agents using keep-alive, getPeerCertificate() may return an empty object on subsequent requests to the same host. To avoid this, disable the agent:
const resp…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants