Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit 7a0ca2a

Browse files
committed
Bug fixes
1 parent 48b489e commit 7a0ca2a

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/main/java/com/kttdevelopment/simplehttpserver/HttpSessionHandler.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,11 @@ public synchronized String assignSessionID(final HttpExchange exchange){
5757
return id;
5858
}
5959

60-
private final Predicate<Headers> hasSetHeader = new Predicate<>() {
61-
@Override
62-
public boolean test(final Headers headers){
63-
if(headers.containsKey("Set-Cookie"))
64-
for(final String value : headers.get("Set-Cookie"))
65-
if(value.startsWith(cookie + "="))
66-
return true;
67-
return false;
68-
}
69-
};
70-
7160
private String getSetSession(final Headers headers){
7261
if(headers.containsKey("Set-Cookie"))
7362
for(final String value : headers.get("Set-Cookie"))
74-
if(value.startsWith(cookie + "=")){
75-
return value.substring(value.indexOf(cookie + '=') + 1,value.indexOf(";"));
63+
if(value.startsWith(cookie + "="))
64+
return value.substring(cookie.length() + 1,value.indexOf(";"));
7665
return null;
7766
}
7867

@@ -100,14 +89,12 @@ public final HttpSession getSession(final HttpExchange exchange){
10089
}
10190
}
10291

103-
final String cookieSessionId, setCookieSessionId;
92+
final String setSession = getSetSession(exchange.getResponseHeaders());
93+
sessionId = setSession != null ? setSession : cookies.get(cookie);
10494

10595
synchronized(this){
106-
if(
107-
((cookieSessionId = cookies.get(cookie)) == null || !sessions.containsKey(sessionId) ) && (setCookieSessionId = getSetSession(exchange.getResponseHeaders())) == null
108-
){
96+
if(!sessions.containsKey(sessionId)){
10997
session = new HttpSession() {
110-
11198
private final String sessionID;
11299
private final long creationTime;
113100
private long lastAccessTime;
@@ -168,7 +155,6 @@ public final String toString(){
168155
session = sessions.get(sessionId);
169156
}
170157
}
171-
System.out.println(sessions);
172158
return session;
173159
}
174160

src/main/java/com/kttdevelopment/simplehttpserver/handler/SessionThrottler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ final boolean addConnection(final HttpExchange exchange){
118118
return true;
119119
}else{
120120
synchronized(this){
121-
final AtomicInteger conn = sessions.get(session);
121+
final AtomicInteger conn;
122+
if(!sessions.containsKey(session))
123+
sessions.put(session,conn = new AtomicInteger(0));
124+
else
125+
conn = sessions.get(session);
122126
if(conn.get() + 1 <= maxConnections.get()){
123127
conn.incrementAndGet();
124128
return true;

0 commit comments

Comments
 (0)