Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove session on 4xx response from WebSocket handshake #25608

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,6 +34,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -270,6 +271,7 @@ else if (transportType.supportsCors()) {
}

SockJsSession session = this.sessions.get(sessionId);
boolean newSession = false;
if (session == null) {
if (transportHandler instanceof SockJsSessionFactory) {
Map<String, Object> attributes = new HashMap<>();
Expand All @@ -278,6 +280,7 @@ else if (transportType.supportsCors()) {
}
SockJsSessionFactory sessionFactory = (SockJsSessionFactory) transportHandler;
session = createSockJsSession(sessionId, sessionFactory, handler, attributes);
newSession = true;
}
else {
response.setStatusCode(HttpStatus.NOT_FOUND);
Expand Down Expand Up @@ -311,6 +314,14 @@ else if (transportType.supportsCors()) {
}

transportHandler.handleRequest(request, response, handler, session);

if (newSession && (response instanceof ServletServerHttpResponse)) {
int status = ((ServletServerHttpResponse) response).getServletResponse().getStatus();
if (HttpStatus.valueOf(status).is4xxClientError()) {
sessions.remove(sessionId);
}
}

chain.applyAfterHandshake(request, response, null);
}
catch (SockJsException ex) {
Expand Down