diff options
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)); |