Skip to content

Commit 913967f

Browse files
committed
Slight (internal?) API change: the SSL handling is entirely encapsulated in the Connection class. Kept the client.ssl prop for now, as that is technically on the public API, but undocumented.
1 parent 0096856 commit 913967f

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

packages/pg/lib/client.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,8 @@ class Client extends EventEmitter {
5656
this.binary = c.binary || defaults.binary
5757
this.processID = null
5858
this.secretKey = null
59+
// TODO: remove in next major release?
5960
this.ssl = this.connectionParameters.ssl || false
60-
// As with Password, make SSL->Key (the private key) non-enumerable.
61-
// It won't show up in stack traces
62-
// or if the client is console.logged
63-
if (this.ssl && this.ssl.key) {
64-
Object.defineProperty(this.ssl, 'key', {
65-
enumerable: false,
66-
})
67-
}
6861

6962
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
7063
}
@@ -115,14 +108,6 @@ class Client extends EventEmitter {
115108

116109
// once connection is established send startup message
117110
con.on('connect', function () {
118-
if (self.ssl) {
119-
con.requestSsl()
120-
} else {
121-
con.startup(self.getStartupConf())
122-
}
123-
})
124-
125-
con.on('sslconnect', function () {
126111
con.startup(self.getStartupConf())
127112
})
128113

packages/pg/lib/connection.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ class Connection extends EventEmitter {
1616
super()
1717
config = config || {}
1818

19+
// As with Password, make SSL->Key (the private key) non-enumerable.
20+
// It won't show up in stack traces
21+
// or if the client is console.logged
22+
if (config.ssl && config.ssl.key) {
23+
Object.defineProperty(config.ssl, 'key', {
24+
enumerable: false,
25+
})
26+
}
27+
1928
this.stream = config.stream || getStream(config.ssl)
2029
if (typeof this.stream === 'function') {
2130
this.stream = this.stream(config)
@@ -47,7 +56,11 @@ class Connection extends EventEmitter {
4756
if (self._keepAlive) {
4857
self.stream.setKeepAlive(true, self._keepAliveInitialDelayMillis)
4958
}
50-
self.emit('connect')
59+
if (self.ssl) {
60+
self.requestSsl()
61+
} else {
62+
self.emit('connect')
63+
}
5164
})
5265

5366
const reportStreamError = function (error) {
@@ -104,7 +117,7 @@ class Connection extends EventEmitter {
104117
self.attachListeners(self.stream)
105118
self.stream.on('error', reportStreamError)
106119

107-
self.emit('sslconnect')
120+
self.emit('connect')
108121
})
109122
}
110123

packages/pg/test/unit/connection/error-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var SSLNegotiationPacketTests = [
4242
testName: 'connection does not emit ECONNRESET errors during disconnect also when using SSL',
4343
errorMessage: null,
4444
response: 'S',
45-
responseType: 'sslconnect',
45+
responseType: 'connect',
4646
},
4747
{
4848
testName: 'connection emits an error when SSL is not supported',

0 commit comments

Comments
 (0)