Browse Source
Merge pull request #630 from Yuanxiangz/master_593
Fix #593: add randomSession config
master
Nikita Koksharov
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
31 additions and
16 deletions
-
src/main/java/com/corundumstudio/socketio/Configuration.java
-
src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java
|
|
@ -86,6 +86,8 @@ public class Configuration { |
|
|
|
|
|
|
|
private boolean websocketCompression = true; |
|
|
|
|
|
|
|
private boolean randomSession = false; |
|
|
|
|
|
|
|
public Configuration() { |
|
|
|
} |
|
|
|
|
|
|
@ -151,6 +153,7 @@ public class Configuration { |
|
|
|
|
|
|
|
setHttpCompression(conf.isHttpCompression()); |
|
|
|
setWebsocketCompression(conf.isWebsocketCompression()); |
|
|
|
setRandomSession(conf.randomSession); |
|
|
|
} |
|
|
|
|
|
|
|
public JsonSupport getJsonSupport() { |
|
|
@ -574,4 +577,11 @@ public class Configuration { |
|
|
|
return websocketCompression; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isRandomSession() { |
|
|
|
return randomSession; |
|
|
|
} |
|
|
|
|
|
|
|
public void setRandomSession(boolean randomSession) { |
|
|
|
this.randomSession = randomSession; |
|
|
|
} |
|
|
|
} |
|
|
@ -165,7 +165,12 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
UUID sessionId = this.generateOrGetSessionIdFromRequest(req.headers()); |
|
|
|
UUID sessionId = null; |
|
|
|
if (configuration.isRandomSession()) { |
|
|
|
sessionId = UUID.randomUUID(); |
|
|
|
} else { |
|
|
|
sessionId = this.generateOrGetSessionIdFromRequest(req.headers()); |
|
|
|
} |
|
|
|
|
|
|
|
List<String> transportValue = params.get("transport"); |
|
|
|
if (transportValue == null) { |
|
|
@ -208,9 +213,9 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
This method will either generate a new random sessionId or will retrieve the value stored |
|
|
|
in the "io" cookie. Failures to parse will cause a logging warning to be generated and a |
|
|
|
random uuid to be generated instead (same as not passing a cookie in the first place). |
|
|
|
* This method will either generate a new random sessionId or will retrieve the value stored |
|
|
|
* in the "io" cookie. Failures to parse will cause a logging warning to be generated and a |
|
|
|
* random uuid to be generated instead (same as not passing a cookie in the first place). |
|
|
|
*/ |
|
|
|
private UUID generateOrGetSessionIdFromRequest(HttpHeaders headers) { |
|
|
|
List<String> values = headers.getAll("io"); |
|
|
|