You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.2 KiB
57 lines
2.2 KiB
/** |
|
* Copyright (c) 2012-2019 Nikita Koksharov |
|
* |
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
* you may not use this file except in compliance with the License. |
|
* You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
package com.fr.third.socketio.handler; |
|
|
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; |
|
|
|
import org.slf4j.Logger; |
|
import org.slf4j.LoggerFactory; |
|
|
|
import io.netty.channel.Channel; |
|
import io.netty.channel.ChannelFuture; |
|
import io.netty.channel.ChannelFutureListener; |
|
import io.netty.channel.ChannelHandler.Sharable; |
|
import io.netty.channel.ChannelHandlerContext; |
|
import io.netty.channel.ChannelInboundHandlerAdapter; |
|
import io.netty.handler.codec.http.DefaultHttpResponse; |
|
import io.netty.handler.codec.http.FullHttpRequest; |
|
import io.netty.handler.codec.http.HttpResponse; |
|
import io.netty.handler.codec.http.HttpResponseStatus; |
|
import io.netty.handler.codec.http.QueryStringDecoder; |
|
|
|
@Sharable |
|
public class WrongUrlHandler extends ChannelInboundHandlerAdapter { |
|
|
|
private static final Logger log = LoggerFactory.getLogger(WrongUrlHandler.class); |
|
|
|
@Override |
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { |
|
if (msg instanceof FullHttpRequest) { |
|
FullHttpRequest req = (FullHttpRequest) msg; |
|
Channel channel = ctx.channel(); |
|
QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri()); |
|
|
|
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST); |
|
ChannelFuture f = channel.writeAndFlush(res); |
|
f.addListener(ChannelFutureListener.CLOSE); |
|
req.release(); |
|
log.warn("Blocked wrong socket.io-context request! url: {}, params: {}, ip: {}", queryDecoder.path(), queryDecoder.parameters(), channel.remoteAddress()); |
|
return; |
|
} |
|
super.channelRead(ctx, msg); |
|
} |
|
|
|
}
|
|
|