|
34 | 34 | import java.net.http.HttpClient; |
35 | 35 | import java.util.List; |
36 | 36 | import java.util.Map; |
| 37 | +import java.util.concurrent.ExecutorService; |
| 38 | +import java.util.concurrent.Executors; |
37 | 39 | import java.util.concurrent.TimeUnit; |
38 | 40 |
|
39 | 41 | public class AuthHookHttpServer { |
40 | 42 |
|
41 | 43 | private final InetSocketAddress bindAddress; |
42 | 44 | private final ChannelFuture channelFuture; |
43 | 45 | private final Map<String, ProxyConnection> pendingConnections = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).<String, ProxyConnection>build().asMap(); |
| 46 | + private final HttpClient httpClient = HttpClient.newBuilder().executor(Executors.newCachedThreadPool()).build(); |
44 | 47 |
|
45 | 48 | public AuthHookHttpServer(final InetSocketAddress bindAddress) { |
46 | 49 | this.bindAddress = bindAddress; |
@@ -100,7 +103,6 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) { |
100 | 103 | } |
101 | 104 | } |
102 | 105 |
|
103 | | - final HttpClient httpClient = HttpClient.newHttpClient(); |
104 | 106 | httpClient.sendAsync(java.net.http.HttpRequest.newBuilder().uri(URI.create("https://sessionserver.mojang.com" + uri)).build(), java.net.http.HttpResponse.BodyHandlers.ofByteArray()) |
105 | 107 | .thenAccept(response -> { |
106 | 108 | final FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.statusCode()), ctx.alloc().buffer()); |
@@ -137,6 +139,13 @@ public void stop() { |
137 | 139 | if (this.channelFuture != null) { |
138 | 140 | this.channelFuture.channel().close(); |
139 | 141 | } |
| 142 | + this.httpClient.executor().map(ExecutorService.class::cast).ifPresent(ExecutorService::shutdown); |
| 143 | + if (this.httpClient instanceof AutoCloseable closeable) { |
| 144 | + try { |
| 145 | + closeable.close(); |
| 146 | + } catch (Exception ignored) { |
| 147 | + } |
| 148 | + } |
140 | 149 | } |
141 | 150 |
|
142 | 151 | public Channel getChannel() { |
|
0 commit comments