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

Commit

Permalink
Merge pull request #91 from libgraviton/feature/remove-okhttp
Browse files Browse the repository at this point in the history
add another param
  • Loading branch information
narcoticfresh authored Dec 7, 2023
2 parents 8bc8588 + 365299f commit 342f6db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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

0 comments on commit 342f6db

Please sign in to comment.