Skip to content

Commit

Permalink
Issue #2 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita committed May 14, 2012
1 parent 7f0664c commit 1f8a488
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/corundumstudio/socketio/AuthorizeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.corundumstudio.socketio;

import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;

import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
Expand All @@ -26,13 +28,18 @@
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -70,6 +77,12 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
HttpRequest req = (HttpRequest) msg;
Channel channel = ctx.getChannel();
QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());
if (!queryDecoder.getPath().startsWith(connectPath)) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
ChannelFuture f = channel.write(res);
f.addListener(ChannelFutureListener.CLOSE);
return;
}
if (HttpMethod.GET.equals(req.getMethod()) && queryDecoder.getPath().equals(connectPath)) {
authorize(channel, req, queryDecoder.getParameters());
return;
Expand Down

0 comments on commit 1f8a488

Please sign in to comment.