Skip to content

Commit db8bf69

Browse files
author
Stephane Landelle
committed
Don't compute SSLContext over and over again, port e8d7662 to master
1 parent 0097294 commit db8bf69

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

api/src/main/java/org/asynchttpclient/util/SslUtils.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
public class SslUtils {
3737

38+
private static SSLContext context = null;
39+
3840
public static SSLEngine getSSLEngine()
3941
throws GeneralSecurityException, IOException {
4042
SSLEngine engine = null;
@@ -50,12 +52,16 @@ public static SSLEngine getSSLEngine()
5052

5153
public static SSLContext getSSLContext()
5254
throws GeneralSecurityException, IOException {
53-
SSLConfig config = new SSLConfig();
54-
if (config.keyStoreLocation == null || config.trustStoreLocation == null) {
55-
return getLooseSSLContext();
56-
} else {
57-
return getStrictSSLContext(config);
58-
}
55+
if (context == null) {
56+
SSLConfig config = new SSLConfig();
57+
if (config.keyStoreLocation == null
58+
|| config.trustStoreLocation == null) {
59+
context = getLooseSSLContext();
60+
} else {
61+
context = getStrictSSLContext(config);
62+
}
63+
}
64+
return context;
5965
}
6066

6167
static SSLContext getStrictSSLContext(SSLConfig config)

0 commit comments

Comments
 (0)