@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel()); disconnectScheduler.cancel(key); if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg; Channel channel = ctx.channel(); QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri()); if (!configuration.isAllowCustomRequests() && !queryDecoder.path().startsWith(connectPath)) { HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST); channel.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE); req.release(); return; } List<String> sid = queryDecoder.parameters().get("sid"); if (queryDecoder.path().equals(connectPath) && sid == null) { String origin = req.headers().get(HttpHeaderNames.ORIGIN); if (!authorize(ctx, channel, origin, queryDecoder.parameters(), req)) { req.release(); return; } // forward message to polling or websocket handler to bind channel } } ctx.fireChannelRead(msg); }
setAllowCustomRequests(conf.isAllowCustomRequests());
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel()); disconnectScheduler.cancel(key); if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg; Channel channel = ctx.channel(); QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri()); if (!configuration.isAllowCustomRequests() && !queryDecoder.path().startsWith(connectPath)) { HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST); channel.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE); req.release(); return; } List<String> sid = queryDecoder.parameters().get("sid"); if (queryDecoder.path().equals(connectPath) && sid == null) { String origin = req.headers().get(HttpHeaderNames.ORIGIN); if (!authorize(ctx, channel, origin, queryDecoder.parameters(), req)) { req.release(); return; } // forward message to polling or websocket handler to bind channel } } ctx.fireChannelRead(msg); }
setAllowCustomRequests(conf.isAllowCustomRequests());