@@ -4,13 +4,15 @@ use std::fmt::{self, Display, Write};
4
4
use std:: path:: { Path , PathBuf } ;
5
5
6
6
pub use ssl_mode:: PgSslMode ;
7
+ pub use ssl_negotiation:: PgSslNegotiation ;
7
8
8
9
use crate :: { connection:: LogSettings , net:: tls:: CertificateInput } ;
9
10
10
11
mod connect;
11
12
mod parse;
12
13
mod pgpass;
13
14
mod ssl_mode;
15
+ mod ssl_negotiation;
14
16
15
17
#[ doc = include_str ! ( "doc.md" ) ]
16
18
#[ derive( Debug , Clone ) ]
@@ -22,6 +24,7 @@ pub struct PgConnectOptions {
22
24
pub ( crate ) password : Option < String > ,
23
25
pub ( crate ) database : Option < String > ,
24
26
pub ( crate ) ssl_mode : PgSslMode ,
27
+ pub ( crate ) ssl_negotiation : PgSslNegotiation ,
25
28
pub ( crate ) ssl_root_cert : Option < CertificateInput > ,
26
29
pub ( crate ) ssl_client_cert : Option < CertificateInput > ,
27
30
pub ( crate ) ssl_client_key : Option < CertificateInput > ,
@@ -85,6 +88,10 @@ impl PgConnectOptions {
85
88
. ok ( )
86
89
. and_then ( |v| v. parse ( ) . ok ( ) )
87
90
. unwrap_or_default ( ) ,
91
+ ssl_negotiation : var ( "PGSSLNEGOTIATION" )
92
+ . ok ( )
93
+ . and_then ( |v| v. parse ( ) . ok ( ) )
94
+ . unwrap_or_default ( ) ,
88
95
statement_cache_capacity : 100 ,
89
96
application_name : var ( "PGAPPNAME" ) . ok ( ) ,
90
97
extra_float_digits : Some ( "2" . into ( ) ) ,
@@ -218,6 +225,26 @@ impl PgConnectOptions {
218
225
self
219
226
}
220
227
228
+ /// Sets the protocol with which the secure SSL TCP/IP connection will be negotiated with
229
+ /// the server.
230
+ ///
231
+ /// By default, the protocol is [`Postgres`](PgSslNegotiation::Postgres), and the client will
232
+ /// first check whether the server supports SSL, and fallback to a non-SSL connection if not.
233
+ ///
234
+ /// Ignored for Unix domain socket communication.
235
+ ///
236
+ /// # Example
237
+ ///
238
+ /// ```rust
239
+ /// # use sqlx_postgres::{PgSslNegotiation, PgConnectOptions};
240
+ /// let options = PgConnectOptions::new()
241
+ /// .ssl_negotiation(PgSslNegotiation::Postgres);
242
+ /// ```
243
+ pub fn ssl_negotiation ( mut self , procedure : PgSslNegotiation ) -> Self {
244
+ self . ssl_negotiation = procedure;
245
+ self
246
+ }
247
+
221
248
/// Sets the name of a file containing SSL certificate authority (CA) certificate(s).
222
249
/// If the file exists, the server's certificate will be verified to be signed by
223
250
/// one of these authorities.
@@ -546,6 +573,19 @@ impl PgConnectOptions {
546
573
self . ssl_mode
547
574
}
548
575
576
+ /// Get the SSL negotiation protocol.
577
+ ///
578
+ /// # Example
579
+ ///
580
+ /// ```rust
581
+ /// # use sqlx_postgres::{PgConnectOptions, PgSslNegotiation};
582
+ /// let options = PgConnectOptions::new();
583
+ /// assert!(matches!(options.get_ssl_negotiation(), PgSslNegotiation::Postgres));
584
+ /// ```
585
+ pub fn get_ssl_negotiation ( & self ) -> PgSslNegotiation {
586
+ self . ssl_negotiation
587
+ }
588
+
549
589
/// Get the application name.
550
590
///
551
591
/// # Example
0 commit comments