From eb3c47330494e8612ae98195f1527999b51ca759 Mon Sep 17 00:00:00 2001 From: Walkyst <41806921+Walkyst@users.noreply.github.com> Date: Fri, 3 Mar 2023 00:23:20 +0300 Subject: [PATCH] Ability to set custom socket factory --- .../tools/http/ExtendedHttpClientBuilder.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/main/src/main/java/com/sedmelluq/discord/lavaplayer/tools/http/ExtendedHttpClientBuilder.java b/main/src/main/java/com/sedmelluq/discord/lavaplayer/tools/http/ExtendedHttpClientBuilder.java index 50c2c800f..f4cf24556 100644 --- a/main/src/main/java/com/sedmelluq/discord/lavaplayer/tools/http/ExtendedHttpClientBuilder.java +++ b/main/src/main/java/com/sedmelluq/discord/lavaplayer/tools/http/ExtendedHttpClientBuilder.java @@ -47,6 +47,8 @@ public class ExtendedHttpClientBuilder extends HttpClientBuilder { private SSLContext sslContextOverride; private String[] sslSupportedProtocols; + private PlainConnectionSocketFactory plainSocketFactory; + private SSLConnectionSocketFactory sslSocketFactory; private ConnectionManagerFactory connectionManagerFactory = ExtendedHttpClientBuilder::createDefaultConnectionManager; @Override @@ -70,6 +72,14 @@ public void setSslSupportedProtocols(String[] protocols) { this.sslSupportedProtocols = protocols; } + public void setPlainConnectionSocketFactory(PlainConnectionSocketFactory plainSocketFactory) { + this.plainSocketFactory = plainSocketFactory; + } + + public void setSslConnectionSocketFactory(SSLConnectionSocketFactory sslSocketFactory) { + this.sslSocketFactory = sslSocketFactory; + } + public void setConnectionManagerFactory(ConnectionManagerFactory factory) { this.connectionManagerFactory = factory; } @@ -88,12 +98,12 @@ private HttpClientConnectionManager createConnectionManager() { private Registry createConnectionSocketFactory() { HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault()); - ConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContextOverride != null ? + ConnectionSocketFactory defaultSslSocketFactory = new SSLConnectionSocketFactory(sslContextOverride != null ? sslContextOverride : defaultSslContext, sslSupportedProtocols, null, hostnameVerifier); return RegistryBuilder.create() - .register("http", PlainConnectionSocketFactory.getSocketFactory()) - .register("https", sslSocketFactory) + .register("http", plainSocketFactory != null ? plainSocketFactory : PlainConnectionSocketFactory.getSocketFactory()) + .register("https", sslSocketFactory != null ? sslSocketFactory : defaultSslSocketFactory) .build(); }