mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Lazily initialise Http client
This commit is contained in:
parent
620b0c898c
commit
df5240a67c
@ -38,12 +38,21 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class HttpClient {
|
public class HttpClient {
|
||||||
|
|
||||||
private static final OkHttpClient CLIENT = new OkHttpClient.Builder()
|
private static OkHttpClient client = new OkHttpClient.Builder()
|
||||||
.addInterceptor(new LuckPermsUserAgentInterceptor())
|
.addInterceptor(new LuckPermsUserAgentInterceptor())
|
||||||
.build();
|
.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 {
|
public static Response makeCall(Request request) throws IOException {
|
||||||
Response response = CLIENT.newCall(request).execute();
|
Response response = getClient().newCall(request).execute();
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
throw exceptionForUnsuccessfulResponse(response);
|
throw exceptionForUnsuccessfulResponse(response);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user