@@ -76,11 +76,11 @@ protected Future<Connection> doConnectInternal(SqlConnectOptions options, Contex
76
76
return context .failedFuture (e );
77
77
}
78
78
SocketAddress server = options .getSocketAddress ();
79
- return doConnect (server , context , options );
79
+ return connect (server , context , true , pgOptions );
80
80
}
81
81
82
82
public void cancelRequest (PgConnectOptions options , int processId , int secretKey , Handler <AsyncResult <Void >> handler ) {
83
- doConnect (options .getSocketAddress (), vertx .createEventLoopContext (), options ).onComplete (ar -> {
83
+ connect (options .getSocketAddress (), vertx .createEventLoopContext (), false , options ).onComplete (ar -> {
84
84
if (ar .succeeded ()) {
85
85
PgSocketConnection conn = (PgSocketConnection ) ar .result ();
86
86
conn .sendCancelRequestMessage (processId , secretKey , handler );
@@ -90,52 +90,56 @@ public void cancelRequest(PgConnectOptions options, int processId, int secretKey
90
90
});
91
91
}
92
92
93
- private Future <Connection > doConnect (SocketAddress server , ContextInternal context , PgConnectOptions options ) {
93
+ private Future <Connection > connect (SocketAddress server , ContextInternal context , boolean sendStartupMessage , PgConnectOptions options ) {
94
94
SslMode sslMode = options .isUsingDomainSocket () ? SslMode .DISABLE : options .getSslMode ();
95
95
Future <Connection > connFuture ;
96
96
switch (sslMode ) {
97
97
case DISABLE :
98
- connFuture = doConnect (server , options , context , false , options );
98
+ connFuture = connect (server , options , context , false , sendStartupMessage );
99
99
break ;
100
100
case ALLOW :
101
- connFuture = doConnect (server , options , context ,false , options ).recover (err -> doConnect (server , options , context ,true , options ));
101
+ connFuture = connect (server , options , context ,false , sendStartupMessage ).recover (err -> connect (server , options , context , true , sendStartupMessage ));
102
102
break ;
103
103
case PREFER :
104
- connFuture = doConnect (server , options , context ,true , options ).recover (err -> doConnect (server , options , context ,false , options ));
104
+ connFuture = connect (server , options , context ,true , sendStartupMessage ).recover (err -> connect (server , options , context , false , sendStartupMessage ));
105
105
break ;
106
106
case REQUIRE :
107
107
case VERIFY_CA :
108
108
case VERIFY_FULL :
109
- connFuture = doConnect (server , options , context , true , options );
109
+ connFuture = connect (server , options , context , true , sendStartupMessage );
110
110
break ;
111
111
default :
112
112
return context .failedFuture (new IllegalArgumentException ("Unsupported SSL mode" ));
113
113
}
114
114
return connFuture ;
115
115
}
116
116
117
- private Future <Connection > doConnect (SocketAddress server , PgConnectOptions connectOptions , ContextInternal context , boolean ssl , PgConnectOptions options ) {
118
- return doConnect_ (server , connectOptions , context , ssl , options ).flatMap (conn -> {
119
- String username = options .getUser ();
120
- String password = options .getPassword ();
121
- String database = options .getDatabase ();
122
- Map <String , String > properties = options .getProperties () != null ? Collections .unmodifiableMap (options .getProperties ()) : null ;
123
- PgSocketConnection socket = (PgSocketConnection ) conn ;
124
- socket .init ();
125
- return Future .<Connection >future (p -> socket .sendStartupMessage (username , password , database , properties , p ))
126
- .map (conn );
127
- });
117
+ private Future <Connection > connect (SocketAddress server , PgConnectOptions connectOptions , ContextInternal context , boolean ssl , boolean sendStartupMessage ) {
118
+ Future <Connection > res = doConnect (server , connectOptions , context , ssl );
119
+ if (sendStartupMessage ) {
120
+ return res .flatMap (conn -> {
121
+ PgSocketConnection socket = (PgSocketConnection ) conn ;
122
+ socket .init ();
123
+ String username = connectOptions .getUser ();
124
+ String password = connectOptions .getPassword ();
125
+ String database = connectOptions .getDatabase ();
126
+ Map <String , String > properties = connectOptions .getProperties () != null ? Collections .unmodifiableMap (connectOptions .getProperties ()) : null ;
127
+ return Future .future (p -> socket .sendStartupMessage (username , password , database , properties , p ));
128
+ });
129
+ } else {
130
+ return res ;
131
+ }
128
132
}
129
133
130
- private Future <Connection > doConnect_ (SocketAddress server , PgConnectOptions connectOptions , ContextInternal context , boolean ssl , PgConnectOptions options ) {
134
+ private Future <Connection > doConnect (SocketAddress server , PgConnectOptions connectOptions , ContextInternal context , boolean ssl ) {
131
135
Future <NetSocket > soFut ;
132
136
try {
133
- soFut = netClient (options ).connect (server , (String ) null );
137
+ soFut = netClient (connectOptions ).connect (server , (String ) null );
134
138
} catch (Exception e ) {
135
139
// Client is closed
136
140
return context .failedFuture (e );
137
141
}
138
- Future <Connection > connFut = soFut .map (so -> newSocketConnection (context , (NetSocketInternal ) so , options ));
142
+ Future <Connection > connFut = soFut .map (so -> newSocketConnection (context , (NetSocketInternal ) so , connectOptions ));
139
143
if (ssl && !server .isDomainSocket ()) {
140
144
// upgrade connection to SSL if needed
141
145
connFut = connFut .flatMap (conn -> Future .future (p -> {
0 commit comments