Skip to content

Commit

Permalink
lazy-load tls (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamingr authored Jan 30, 2022
1 parent c85bb04 commit 72c2a51
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/core/connect.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const net = require('net')
const tls = require('tls')
const assert = require('assert')
const util = require('./util')
const { InvalidArgumentError, ConnectTimeoutError } = require('./errors')
let tls // include tls conditionally since it is not always available

// TODO: session re-use does not wait for the first
// connection to resolve the session and might therefore
Expand All @@ -24,6 +24,9 @@ function buildConnector ({ maxCachedSessions, socketPath, timeout, ...opts }) {
return function connect ({ hostname, host, protocol, port, servername }, callback) {
let socket
if (protocol === 'https:') {
if (!tls) {
tls = require('tls')
}
servername = servername || options.servername || util.getServerName(host) || null

const sessionKey = servername || hostname
Expand Down

0 comments on commit 72c2a51

Please sign in to comment.