Skip to content

Commit e8d7662

Browse files
author
Stephane Landelle
committed
Don't compute SSLContext over and over again
1 parent 223641f commit e8d7662

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/java/com/ning/http/util/SslUtils.java

Lines changed: 11 additions & 5 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);
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+
}
5863
}
64+
return context;
5965
}
6066

6167
static SSLContext getStrictSSLContext(SSLConfig config)

0 commit comments

Comments
 (0)