3 changed files with 54 additions and 8 deletions
-
22src/main/java/com/corundumstudio/socketio/SocketIOChannelInitializer.java
-
1src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java
-
39src/main/java/com/corundumstudio/socketio/handler/WrongUrlHandler.java
@ -0,0 +1,39 @@ |
|||||
|
package com.corundumstudio.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.ChannelHandlerContext; |
||||
|
import io.netty.channel.ChannelInboundHandlerAdapter; |
||||
|
import io.netty.channel.ChannelHandler.Sharable; |
||||
|
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 final Logger log = LoggerFactory.getLogger(getClass()); |
||||
|
|
||||
|
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.getUri()); |
||||
|
|
||||
|
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST); |
||||
|
ChannelFuture f = channel.write(res); |
||||
|
f.addListener(ChannelFutureListener.CLOSE); |
||||
|
req.release(); |
||||
|
log.warn("Blocked wrong socket.io-context request! url: {}, ip: {}", queryDecoder.path(), channel.remoteAddress()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue