This commit is contained in:
Sollace 2022-12-11 14:00:37 +00:00
parent 39c00bbfb1
commit cab2d3d952
7 changed files with 16 additions and 15 deletions

View file

@ -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);

View file

@ -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.
*/

View file

@ -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))

View file

@ -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());
}

View file

@ -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;
}

View file

@ -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<MoreHttpResponses> async(Executor exec) {

View file

@ -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);
}