MCPcopy Create free account
hub / github.com/porsager/postgres / secure

Function secure

deno/src/connection.js:269–297  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

267 }
268
269 async function secure() {
270 if (sslnegotiation !== 'direct') {
271 write(SSLRequest)
272 const canSSL = await new Promise(r => socket.once('data', x => r(x[0] === 83))) // S
273
274 if (!canSSL && ssl === 'prefer')
275 return connected()
276 }
277
278 const options = {
279 socket,
280 servername: net.isIP(socket.host) ? undefined : socket.host
281 }
282
283 if (sslnegotiation === 'direct')
284 options.ALPNProtocols = ['postgresql']
285
286 if (ssl === 'require' || ssl === 'allow' || ssl === 'prefer')
287 options.rejectUnauthorized = false
288 else if (typeof ssl === 'object')
289 Object.assign(options, ssl)
290
291 socket.removeAllListeners()
292 socket = tls.connect(options)
293 socket.on('secureConnect', connected)
294 socket.on('error', error)
295 socket.on('close', closed)
296 socket.on('drain', drain)
297 }
298
299 /* c8 ignore next 3 */
300 function drain() {

Callers 1

connectFunction · 0.70

Calls 2

writeFunction · 0.70
connectedFunction · 0.70

Tested by

no test coverage detected