mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Polish WebSession support and tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -107,12 +107,12 @@ public interface ServerWebExchange {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the web session for the current request. Always guaranteed to
|
||||
* return an instance either matching to the session id requested by the
|
||||
* client, or with a new session id either because the client did not
|
||||
* specify one or because the underlying session had expired. Use of this
|
||||
* method does not automatically create a session. See {@link WebSession}
|
||||
* for more details.
|
||||
* Return the web session for the current request.
|
||||
* <p>Always guaranteed to return either an instance matching the session id
|
||||
* requested by the client, or a new session either because the client did not
|
||||
* specify a session id or because the underlying session expired.
|
||||
* <p>Use of this method does not automatically create a session. See
|
||||
* {@link WebSession} for more details.
|
||||
*/
|
||||
Mono<WebSession> getSession();
|
||||
|
||||
|
||||
+13
-11
@@ -79,9 +79,9 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@link Clock} to use to set lastAccessTime on every created
|
||||
* session and to calculate if it is expired.
|
||||
* <p>This may be useful to align to different timezone or to set the clock
|
||||
* Configure the {@link Clock} to use to set the {@code lastAccessTime} on
|
||||
* every created session and to calculate if the session has expired.
|
||||
* <p>This may be useful to align to different time zones or to set the clock
|
||||
* back in a test, for example, {@code Clock.offset(clock, Duration.ofMinutes(-31))}
|
||||
* in order to simulate session expiration.
|
||||
* <p>By default this is {@code Clock.system(ZoneId.of("GMT"))}.
|
||||
@@ -94,16 +94,17 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured clock for session lastAccessTime calculations.
|
||||
* Return the configured clock for session {@code lastAccessTime} calculations.
|
||||
*/
|
||||
public Clock getClock() {
|
||||
return this.clock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map of sessions with an {@link Collections#unmodifiableMap
|
||||
* unmodifiable} wrapper. This could be used for management purposes, to
|
||||
* list active sessions, invalidate expired ones, etc.
|
||||
* Return an {@linkplain Collections#unmodifiableMap unmodifiable} copy of the
|
||||
* map of sessions.
|
||||
* <p>This could be used for management purposes, to list active sessions,
|
||||
* to invalidate expired sessions, etc.
|
||||
* @since 5.0.8
|
||||
*/
|
||||
public Map<String, WebSession> getSessions() {
|
||||
@@ -157,10 +158,11 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for expired sessions and remove them. Typically such checks are
|
||||
* kicked off lazily during calls to {@link #createWebSession() create} or
|
||||
* {@link #retrieveSession retrieve}, no less than 60 seconds apart.
|
||||
* This method can be called to force a check at a specific time.
|
||||
* Check for expired sessions and remove them.
|
||||
* <p>Typically such checks are kicked off lazily during calls to
|
||||
* {@link #createWebSession()} or {@link #retrieveSession}, no less than 60
|
||||
* seconds apart.
|
||||
* <p>This method can be called to force a check at a specific time.
|
||||
* @since 5.0.8
|
||||
*/
|
||||
public void removeExpiredSessions() {
|
||||
|
||||
+4
-4
@@ -32,10 +32,10 @@ import org.springframework.web.server.WebSession;
|
||||
public interface WebSessionManager {
|
||||
|
||||
/**
|
||||
* Return the {@link WebSession} for the given exchange. Always guaranteed
|
||||
* to return an instance either matching to the session id requested by the
|
||||
* client, or a new session either because the client did not specify one
|
||||
* or because the underlying session expired.
|
||||
* Return the {@link WebSession} for the given exchange.
|
||||
* <p>Always guaranteed to return either an instance matching the session id
|
||||
* requested by the client, or a new session either because the client did not
|
||||
* specify a session id or because the underlying session expired.
|
||||
* @param exchange the current exchange
|
||||
* @return promise for the WebSession
|
||||
*/
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ public interface WebSessionStore {
|
||||
* Return the WebSession for the given id.
|
||||
* <p><strong>Note:</strong> This method should perform an expiration check,
|
||||
* and if it has expired remove the session and return empty. This method
|
||||
* should also update the lastAccessTime of retrieved sessions.
|
||||
* should also update the {@code lastAccessTime} of retrieved sessions.
|
||||
* @param sessionId the session to load
|
||||
* @return the session, or an empty {@code Mono}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user