Remove Cookie support from ServerHttpRequest

Although ServletHttpRequest provides access to Cookies, other
implementations may not. At the moment this was only needed
for SockJS to check the value of the JSESSIONID cookie. This
is now down by parsing the raw cookie values locally.

If comprehensive cookie support is to be added, we should
probably consider HttpHeaders as a potential candidate.
This commit is contained in:
Rossen Stoyanchev
2013-08-14 10:15:02 -04:00
parent b232dc9d2b
commit 4c0490a070
5 changed files with 18 additions and 182 deletions

View File

@@ -29,7 +29,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import org.springframework.http.Cookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.ServerHttpRequest;
@@ -307,9 +307,8 @@ public class DefaultSockJsService extends AbstractSockJsService {
}
if (transportType.sendsSessionCookie() && isDummySessionCookieEnabled()) {
Cookie cookie = request.getCookies().get("JSESSIONID");
String value = (cookie != null) ? cookie.getValue() : "dummy";
response.getHeaders().set("Set-Cookie", "JSESSIONID=" + value + ";path=/");
String cookieValue = getJsessionIdCookieValue(request.getHeaders());
response.getHeaders().set("Set-Cookie", "JSESSIONID=" + cookieValue + ";path=/");
}
if (transportType.supportsCors()) {
@@ -387,6 +386,20 @@ public class DefaultSockJsService extends AbstractSockJsService {
}, getDisconnectDelay());
}
private String getJsessionIdCookieValue(HttpHeaders headers) {
List<String> rawCookies = headers.get("Cookie");
if (!CollectionUtils.isEmpty(rawCookies)) {
for (String rawCookie : rawCookies) {
if (rawCookie.startsWith("JSESSIONID=")) {
int start = "JSESSIONID=".length();
int end = rawCookie.indexOf(';');
return (end != -1) ? rawCookie.substring(start, end) : rawCookie.substring(start);
}
}
}
return "dummy";
}
private final SockJsServiceConfig sockJsServiceConfig = new SockJsServiceConfig() {