From df5240a67c1834ba1fb8d7a74a7834bcbfaa51ad Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 15 Feb 2018 22:03:53 +0000 Subject: [PATCH] Lazily initialise Http client --- .../me/lucko/luckperms/common/utils/HttpClient.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/HttpClient.java b/common/src/main/java/me/lucko/luckperms/common/utils/HttpClient.java index 532eb29a..ec4a68da 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/HttpClient.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/HttpClient.java @@ -38,12 +38,21 @@ import java.io.IOException; */ public class HttpClient { - private static final OkHttpClient CLIENT = new OkHttpClient.Builder() + private static OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(new LuckPermsUserAgentInterceptor()) .build(); + private synchronized static OkHttpClient getClient() { + if (client == null) { + client = new OkHttpClient.Builder() + .addInterceptor(new LuckPermsUserAgentInterceptor()) + .build(); + } + return client; + } + public static Response makeCall(Request request) throws IOException { - Response response = CLIENT.newCall(request).execute(); + Response response = getClient().newCall(request).execute(); if (!response.isSuccessful()) { throw exceptionForUnsuccessfulResponse(response); }