diff options
author | Trumeet <yuuta@yuuta.moe> | 2022-07-13 13:44:20 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2022-07-13 13:44:20 -0700 |
commit | 12b3eb07becd97846db5a4d3f3335bd5a0db64d7 (patch) | |
tree | 94ccd5825855abde25c14750ea5281e180bbf80e /src/main/java/moe/ymc/acron | |
parent | 5a24ed8f5b7885d5b60e08ee64d9d47c21667a91 (diff) | |
download | acron-12b3eb07becd97846db5a4d3f3335bd5a0db64d7.tar acron-12b3eb07becd97846db5a4d3f3335bd5a0db64d7.tar.gz acron-12b3eb07becd97846db5a4d3f3335bd5a0db64d7.tar.bz2 acron-12b3eb07becd97846db5a4d3f3335bd5a0db64d7.zip |
Fix HTTP connection not closed after writing error codes in AuthHandler
Signed-off-by: Trumeet <yuuta@yuuta.moe>
Diffstat (limited to 'src/main/java/moe/ymc/acron')
-rw-r--r-- | src/main/java/moe/ymc/acron/net/AuthHandler.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/moe/ymc/acron/net/AuthHandler.java b/src/main/java/moe/ymc/acron/net/AuthHandler.java index 47abf9f..3e42e14 100644 --- a/src/main/java/moe/ymc/acron/net/AuthHandler.java +++ b/src/main/java/moe/ymc/acron/net/AuthHandler.java @@ -1,5 +1,6 @@ package moe.ymc.acron.net; +import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.*; @@ -24,7 +25,8 @@ public class AuthHandler extends SimpleChannelInboundHandler<HttpRequest> { LOGGER.debug("channelRead0: {}", msg.uri()); if (msg.method() != HttpMethod.GET) { ctx.channel().writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, - HttpResponseStatus.BAD_REQUEST)); + HttpResponseStatus.BAD_REQUEST)) + .addListener(ChannelFutureListener.CLOSE); return; } HttpHeaders headers = msg.headers(); @@ -32,7 +34,8 @@ public class AuthHandler extends SimpleChannelInboundHandler<HttpRequest> { if (!"Upgrade".equalsIgnoreCase(headers.get(HttpHeaderNames.CONNECTION)) || !"WebSocket".equalsIgnoreCase(headers.get(HttpHeaderNames.UPGRADE))) { ctx.channel().writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, - HttpResponseStatus.BAD_REQUEST)); + HttpResponseStatus.BAD_REQUEST)) + .addListener(ChannelFutureListener.CLOSE); return; } @@ -47,7 +50,8 @@ public class AuthHandler extends SimpleChannelInboundHandler<HttpRequest> { decoder.parameters().get("token") == null || decoder.parameters().get("token").size() != 1) { ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, - HttpResponseStatus.BAD_REQUEST)); + HttpResponseStatus.BAD_REQUEST)) + .addListener(ChannelFutureListener.CLOSE); return; } @@ -59,12 +63,14 @@ public class AuthHandler extends SimpleChannelInboundHandler<HttpRequest> { try { if (Integer.parseInt(versionRaw) != 0) { ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, - HttpResponseStatus.BAD_REQUEST)); + HttpResponseStatus.BAD_REQUEST)) + .addListener(ChannelFutureListener.CLOSE); return; } } catch (NumberFormatException ignored) { ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, - HttpResponseStatus.BAD_REQUEST)); + HttpResponseStatus.BAD_REQUEST)) + .addListener(ChannelFutureListener.CLOSE); return; } @@ -72,7 +78,8 @@ public class AuthHandler extends SimpleChannelInboundHandler<HttpRequest> { if (client == null || !client.token().equals(DigestUtils.sha256Hex(token))) { ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, - HttpResponseStatus.UNAUTHORIZED)); + HttpResponseStatus.UNAUTHORIZED)) + .addListener(ChannelFutureListener.CLOSE); return; } ctx.channel().attr(Attributes.ID).set(new ClientIdentification(0, client)); |