diff --git a/src/main/java/com/github/libgraviton/workerbase/di/WorkerBaseProvider.java b/src/main/java/com/github/libgraviton/workerbase/di/WorkerBaseProvider.java index bb68354..f8d85f8 100644 --- a/src/main/java/com/github/libgraviton/workerbase/di/WorkerBaseProvider.java +++ b/src/main/java/com/github/libgraviton/workerbase/di/WorkerBaseProvider.java @@ -80,7 +80,7 @@ public static Methanol getMethanol() throws Exception { final boolean hasRetry = WorkerProperties.HTTP_CLIENT_DORETRY.get().equals("true"); final boolean trustAll = WorkerProperties.HTTP_CLIENT_TLS_TRUST_ALL.get().equals("true"); - return MethanolGatewayFactory.getInstance(hasRetry, trustAll); + return MethanolGatewayFactory.getInstance(hasRetry, trustAll, false); } @Provides diff --git a/src/main/java/com/github/libgraviton/workerbase/gdk/api/gateway/http/MethanolGatewayFactory.java b/src/main/java/com/github/libgraviton/workerbase/gdk/api/gateway/http/MethanolGatewayFactory.java index 3a9e647..a3ca6a1 100644 --- a/src/main/java/com/github/libgraviton/workerbase/gdk/api/gateway/http/MethanolGatewayFactory.java +++ b/src/main/java/com/github/libgraviton/workerbase/gdk/api/gateway/http/MethanolGatewayFactory.java @@ -4,6 +4,9 @@ import com.github.mizosoft.methanol.Methanol; import javax.net.ssl.*; +import java.net.CookieHandler; +import java.net.CookieManager; +import java.net.CookiePolicy; import java.net.Socket; import java.net.http.HttpClient; import java.security.KeyManagementException; @@ -56,12 +59,11 @@ public void checkServerTrusted(java.security.cert.X509Certificate[] chain, Strin * * @return instance */ - public static Methanol getInstance(boolean hasRetry, boolean trustAll) throws NoSuchAlgorithmException, KeyManagementException { + public static Methanol getInstance(boolean hasRetry, boolean trustAll, boolean hasCookie) throws NoSuchAlgorithmException, KeyManagementException { Methanol.Builder builder = Methanol.newBuilder(); if (trustAll) { SSLContext sslContext = SSLContext.getInstance("SSL"); // OR TLS sslContext.init(null, new TrustManager[]{MOCK_TRUST_MANAGER}, new SecureRandom()); - builder.sslContext(sslContext); } @@ -69,6 +71,14 @@ public static Methanol getInstance(boolean hasRetry, boolean trustAll) throws No builder.interceptor(new RetryInterceptor()); } + if (hasCookie) { + CookieManager cm = new CookieManager(); + cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL); + CookieHandler.setDefault(cm); + + builder.cookieHandler(CookieHandler.getDefault()); + } + builder.followRedirects(HttpClient.Redirect.ALWAYS); return builder.build();