[FIX] Params Parsing

This commit is contained in:
Gravita 2021-03-24 20:33:35 +07:00
parent 0751d2fd28
commit 1452b59fa5

View file

@ -1,12 +1,10 @@
package pro.gravit.launchserver.socket.handlers; package pro.gravit.launchserver.socket.handlers;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.*;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launchserver.socket.NettyConnectContext; import pro.gravit.launchserver.socket.NettyConnectContext;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
@ -86,7 +84,7 @@ default Map<String, String> getParamsFromUri(String uri) {
continue; continue;
} }
String key = c.substring(0, index); String key = c.substring(0, index);
String value = c.substring(index); String value = c.substring(index+1);
map.put(key, value); map.put(key, value);
} }
return map; return map;
@ -97,11 +95,13 @@ default FullHttpResponse simpleResponse(HttpResponseStatus status, String body)
} }
default FullHttpResponse simpleJsonResponse(HttpResponseStatus status, Object 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) { default void sendHttpResponse(ChannelHandlerContext ctx, FullHttpResponse response) {
ctx.writeAndFlush(response, ctx.voidPromise()); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
} }
} }