diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java index 2edba9e9..216c3ff9 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java @@ -87,7 +87,7 @@ public class LegacySkinServer implements SkinServer { } private MinecraftProfileTexture loadProfileTexture(GameProfile profile, String url) throws IOException { - try (MoreHttpResponses resp = MoreHttpResponses.execute(HTTP_CLIENT, new HttpHead(url))) { + try (MoreHttpResponses resp = MoreHttpResponses.execute(new HttpHead(url))) { resp.requireOk(); logger.debug("Found skin for {} at {}", profile.getName(), url); diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java index 2f13dcb5..d5d247ec 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java @@ -10,12 +10,8 @@ import net.minecraft.util.Session; import java.io.IOException; import java.util.Set; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; public interface SkinServer extends Exposable { - CloseableHttpClient HTTP_CLIENT = HttpClients.createSystem(); - /** * Returns the set of features that this skin server supports. */ diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java index 17e00bd7..a5e41fec 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java @@ -54,7 +54,7 @@ public class ValhallaSkinServer implements SkinServer { @Override public TexturePayload loadProfileData(GameProfile profile) throws IOException, AuthenticationException { - try (MoreHttpResponses response = MoreHttpResponses.execute(HTTP_CLIENT, new HttpGet(getTexturesURI(profile)))) { + try (MoreHttpResponses response = MoreHttpResponses.execute(new HttpGet(getTexturesURI(profile)))) { return response.requireOk().json(TexturePayload.class, "Invalid texture payload"); } } @@ -124,7 +124,7 @@ public class ValhallaSkinServer implements SkinServer { } private void upload(HttpUriRequest request) throws IOException { - try (MoreHttpResponses response = MoreHttpResponses.execute(HTTP_CLIENT, request)) { + try (MoreHttpResponses response = MoreHttpResponses.execute(request)) { response.requireOk(); } } @@ -151,7 +151,7 @@ public class ValhallaSkinServer implements SkinServer { } private AuthHandshake authHandshake(String name) throws IOException { - try (MoreHttpResponses resp = MoreHttpResponses.execute(HTTP_CLIENT, RequestBuilder.post() + try (MoreHttpResponses resp = MoreHttpResponses.execute(RequestBuilder.post() .setUri(getHandshakeURI()) .addParameter("name", name) .build())) { @@ -160,7 +160,7 @@ public class ValhallaSkinServer implements SkinServer { } private AuthResponse authResponse(String name, long verifyToken) throws IOException { - try (MoreHttpResponses resp = MoreHttpResponses.execute(HTTP_CLIENT, RequestBuilder.post() + try (MoreHttpResponses resp = MoreHttpResponses.execute(RequestBuilder.post() .setUri(getResponseURI()) .addParameter("name", name) .addParameter("verifyToken", String.valueOf(verifyToken)) diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/YggdrasilSkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/YggdrasilSkinServer.java index eb446ac5..1d534eb8 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/YggdrasilSkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/YggdrasilSkinServer.java @@ -143,7 +143,7 @@ public class YggdrasilSkinServer implements SkinServer { } private void send(RequestBuilder request) throws IOException { - try (MoreHttpResponses response = MoreHttpResponses.execute(HTTP_CLIENT, request.build())) { + try (MoreHttpResponses response = MoreHttpResponses.execute(request.build())) { if (!response.ok()) { throw new IOException(response.json(ErrorResponse.class, "Server error wasn't in json: {}").toString()); } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/util/MoreHttpResponses.java b/src/hdskins/java/com/voxelmodpack/hdskins/util/MoreHttpResponses.java index 61e08d87..aa2daf0e 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/util/MoreHttpResponses.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/util/MoreHttpResponses.java @@ -13,6 +13,7 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; import java.io.BufferedReader; @@ -26,12 +27,13 @@ import java.util.*; */ @FunctionalInterface public interface MoreHttpResponses extends AutoCloseable { + CloseableHttpClient HTTP_CLIENT = HttpClients.createSystem(); Gson GSON = new GsonBuilder() .registerTypeAdapter(UUID.class, new UUIDTypeAdapter()) .create(); - static MoreHttpResponses execute(CloseableHttpClient client, HttpUriRequest request) throws IOException { - CloseableHttpResponse response = client.execute(request); + static MoreHttpResponses execute(HttpUriRequest request) throws IOException { + CloseableHttpResponse response = HTTP_CLIENT.execute(request); return () -> response; } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/util/NetClient.java b/src/hdskins/java/com/voxelmodpack/hdskins/util/NetClient.java index 71a6ec38..84e3f29f 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/util/NetClient.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/util/NetClient.java @@ -1,7 +1,5 @@ package com.voxelmodpack.hdskins.util; -import com.voxelmodpack.hdskins.server.SkinServer; - import org.apache.http.HttpEntity; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.RequestBuilder; @@ -73,7 +71,7 @@ public class NetClient { } } - return MoreHttpResponses.execute(SkinServer.HTTP_CLIENT, request); + return MoreHttpResponses.execute(request); } public CompletableFuture async(Executor exec) { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/util/SslHelper.java b/src/hdskins/java/com/voxelmodpack/hdskins/util/SslHelper.java index b4b1f6dc..f5fa7fd1 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/util/SslHelper.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/util/SslHelper.java @@ -14,6 +14,7 @@ import java.util.regex.Pattern; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; +import org.apache.http.client.methods.RequestBuilder; import org.apache.logging.log4j.Logger; /** @@ -88,6 +89,10 @@ public class SslHelper { try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { body = reader.readLine(); } + + try (MoreHttpResponses response = MoreHttpResponses.execute(RequestBuilder.get().setUri("https://helloworld.letsencrypt.org").build())) { + response.requireOk(); + } } catch (Exception e) { mod.error("An error occurred whilst adding the Let's Encrypt root certificate. I'm afraid you wont be able to access resources with a Let's Encrypt certificate D:", e); }