From 1452b59fa5452583e575c9e9dde6991dd61e55bf Mon Sep 17 00:00:00 2001 From: Gravita Date: Wed, 24 Mar 2021 20:33:35 +0700 Subject: [PATCH] [FIX] Params Parsing --- .../socket/handlers/NettyWebAPIHandler.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java index a6e3b2c4..0cd2eb28 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java @@ -1,12 +1,10 @@ package pro.gravit.launchserver.socket.handlers; import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.*; import pro.gravit.launcher.Launcher; import pro.gravit.launchserver.socket.NettyConnectContext; import pro.gravit.utils.helper.LogHelper; @@ -86,7 +84,7 @@ default Map getParamsFromUri(String uri) { continue; } String key = c.substring(0, index); - String value = c.substring(index); + String value = c.substring(index+1); map.put(key, value); } return map; @@ -97,11 +95,13 @@ default FullHttpResponse simpleResponse(HttpResponseStatus status, String body) } default FullHttpResponse simpleJsonResponse(HttpResponseStatus status, Object body) { - return new DefaultFullHttpResponse(HTTP_1_1, status, body != null ? Unpooled.wrappedBuffer(Launcher.gsonManager.gson.toJson(body).getBytes()) : Unpooled.buffer()); + DefaultFullHttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, status, body != null ? Unpooled.wrappedBuffer(Launcher.gsonManager.gson.toJson(body).getBytes()) : Unpooled.buffer()); + httpResponse.headers().add(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON); + return httpResponse; } default void sendHttpResponse(ChannelHandlerContext ctx, FullHttpResponse response) { - ctx.writeAndFlush(response, ctx.voidPromise()); + ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } }