Skip to content

Commit cee582d

Browse files
committed
Get TLS config only once
Only get the TLS config once from the shim, and keep it around for re-use.
1 parent 05361bc commit cee582d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ impl<B: MysqlShim<RW>, RW: Read + Write> MysqlIntermediary<B, RW> {
238238
}
239239

240240
fn init(&mut self) -> Result<(), B::Error> {
241+
let tls_conf = self.shim.tls_config();
242+
241243
self.rw.write_all(&[10])?; // protocol 10
242244

243245
// 5.1.10 because that's what Ruby's ActiveRecord requires
@@ -246,7 +248,7 @@ impl<B: MysqlShim<RW>, RW: Read + Write> MysqlIntermediary<B, RW> {
246248
self.rw.write_all(&[0x08, 0x00, 0x00, 0x00])?; // TODO: connection ID
247249
self.rw.write_all(&b";X,po_k}\0"[..])?; // auth seed
248250
let capabilities = &mut [0x00, 0x42]; // 4.1 proto
249-
if self.shim.tls_config().is_some() {
251+
if tls_conf.is_some() {
250252
capabilities[1] |= 0x08; // SSL support flag
251253
}
252254
self.rw.write_all(capabilities)?;
@@ -292,7 +294,7 @@ impl<B: MysqlShim<RW>, RW: Read + Write> MysqlIntermediary<B, RW> {
292294
self.rw.set_seq(seq + 1);
293295

294296
if handshake.capabilities.contains(CapabilityFlags::CLIENT_SSL) {
295-
let config = self.shim.tls_config().ok_or_else(|| {
297+
let config = tls_conf.ok_or_else(|| {
296298
io::Error::new(
297299
io::ErrorKind::InvalidData,
298300
"client requested SSL despite us not advertising support for it",

0 commit comments

Comments
 (0)