Skip to content

Commit

Permalink
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly committed Aug 1, 2019
2 parents ef15c12 + 4f69bd6 commit 6d498fe
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/main/java/com/launchdarkly/eventsource/EventSource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.launchdarkly.eventsource;

import javax.net.ssl.SSLSocketFactory;
import okhttp3.*;
import okio.BufferedSource;
import okio.Okio;
Expand Down Expand Up @@ -512,6 +513,13 @@ public static final class Builder {
.readTimeout(DEFAULT_READ_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.writeTimeout(DEFAULT_WRITE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.retryOnConnectionFailure(true);
{
try {
clientBuilder.sslSocketFactory(new ModernTLSSocketFactory(), defaultTrustManager());
} catch (GeneralSecurityException e) {
// TLS is not available, so don't set up the socket factory, swallow the exception
}
}

/**
* Creates a new builder.
Expand Down Expand Up @@ -752,6 +760,19 @@ public Builder connectionErrorHandler(ConnectionErrorHandler handler) {
return this;
}

/**
* Sets the {@link SSLSocketFactory} for making TLS connections.
*
* @param sslSocketFactory the ssl socket factory
* @param trustManager the trust manager
* @return the builder
*/
public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory,
X509TrustManager trustManager) {
this.clientBuilder.sslSocketFactory(sslSocketFactory, trustManager);
return this;
}

/**
* Constructs an {@link EventSource} using the builder's current properties.
* @return the new EventSource instance
Expand All @@ -761,12 +782,6 @@ public EventSource build() {
clientBuilder.proxy(proxy);
}

try {
clientBuilder.sslSocketFactory(new ModernTLSSocketFactory(), defaultTrustManager());
} catch (GeneralSecurityException e) {
// TLS is not available, so don't set up the socket factory, swallow the exception
}

if (proxyAuthenticator != null) {
clientBuilder.proxyAuthenticator(proxyAuthenticator);
}
Expand Down

0 comments on commit 6d498fe

Please sign in to comment.