Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

add another param #91

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,19 +59,26 @@ 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);
}

if (hasRetry) {
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();
Expand Down