diff --git a/src/main/java/com/corundumstudio/socketio/AuthorizationListener.java b/src/main/java/com/corundumstudio/socketio/AuthorizationListener.java
index 886a076c..39348d57 100644
--- a/src/main/java/com/corundumstudio/socketio/AuthorizationListener.java
+++ b/src/main/java/com/corundumstudio/socketio/AuthorizationListener.java
@@ -18,10 +18,17 @@
public interface AuthorizationListener {
/**
- * Checks is client with handshake data is authorized
+ * Checks if client with handshake data is redirected (307)
+ *
+ * @return - the URL if client is redirected or null otherwise
+ */
+ String isRedirected(HandshakeData data);
+
+ /**
+ * Checks if client with handshake data is authorized
*
* @param data - handshake data
- * @return - true if client is authorized of false otherwise
+ * @return - true if client is authorized or false otherwise
*/
boolean isAuthorized(HandshakeData data);
diff --git a/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java b/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java
index 80bfe3f9..efc7a95b 100644
--- a/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java
+++ b/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java
@@ -146,14 +146,29 @@ private boolean authorize(ChannelHandlerContext ctx, Channel channel, String ori
(InetSocketAddress)channel.remoteAddress(),
req.uri(), origin != null && !origin.equalsIgnoreCase("null"));
- boolean result = false;
+ String redirectUrl = null;
try {
- result = configuration.getAuthorizationListener().isAuthorized(data);
+ redirectUrl = configuration.getAuthorizationListener().isRedirected(data);
+ } catch (Exception ignore) {
+ }
+
+ if (redirectUrl != null) {
+ HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.TEMPORARY_REDIRECT);
+ res.headers().add("Location", redirectUrl);
+ channel.writeAndFlush(res)
+ .addListener(ChannelFutureListener.CLOSE);
+ log.debug("Handshake redirected, query params: {} headers: {}", params, headers);
+ return false;
+ }
+
+ boolean isAuthorized = false;
+ try {
+ isAuthorized = configuration.getAuthorizationListener().isAuthorized(data);
} catch (Exception e) {
log.error("Authorization error", e);
}
- if (!result) {
+ if (!isAuthorized) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
channel.writeAndFlush(res)
.addListener(ChannelFutureListener.CLOSE);
diff --git a/src/main/java/com/corundumstudio/socketio/handler/SuccessAuthorizationListener.java b/src/main/java/com/corundumstudio/socketio/handler/SuccessAuthorizationListener.java
index dfded95c..8e0a3f41 100644
--- a/src/main/java/com/corundumstudio/socketio/handler/SuccessAuthorizationListener.java
+++ b/src/main/java/com/corundumstudio/socketio/handler/SuccessAuthorizationListener.java
@@ -20,6 +20,11 @@
public class SuccessAuthorizationListener implements AuthorizationListener {
+ @Override
+ public String isRedirected(HandshakeData data) {
+ return null;
+ }
+
@Override
public boolean isAuthorized(HandshakeData data) {
return true;