mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Expose handler to ApiVersionDeprecationHandler implementations
Closes gh-35750
This commit is contained in:
+4
-1
@@ -35,9 +35,12 @@ public interface ApiVersionDeprecationHandler {
|
||||
* accordingly, e.g. by setting response headers to signal the deprecation,
|
||||
* to specify relevant dates and provide links to further details.
|
||||
* @param version the resolved and parsed request version
|
||||
* @param handler the handler chosen for the request
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
*/
|
||||
void handleVersion(Comparable<?> version, HttpServletRequest request, HttpServletResponse response);
|
||||
void handleVersion(
|
||||
Comparable<?> version, Object handler,
|
||||
HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
}
|
||||
|
||||
@@ -91,10 +91,12 @@ public interface ApiVersionStrategy {
|
||||
* accordingly, e.g. by setting response headers to signal the deprecation,
|
||||
* to specify relevant dates and provide links to further details.
|
||||
* @param version the resolved and parsed request version
|
||||
* @param handler the handler chosen for the request
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
* @see ApiVersionDeprecationHandler
|
||||
*/
|
||||
void handleDeprecations(Comparable<?> version, HttpServletRequest request, HttpServletResponse response);
|
||||
void handleDeprecations(
|
||||
Comparable<?> version, Object handler, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
}
|
||||
|
||||
+4
-2
@@ -180,9 +180,11 @@ public class DefaultApiVersionStrategy implements ApiVersionStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDeprecations(Comparable<?> version, HttpServletRequest request, HttpServletResponse response) {
|
||||
public void handleDeprecations(
|
||||
Comparable<?> version, Object handler, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
if (this.deprecationHandler != null) {
|
||||
this.deprecationHandler.handleVersion(version, request, response);
|
||||
this.deprecationHandler.handleVersion(version, handler, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -87,7 +87,8 @@ public class StandardApiVersionDeprecationHandler implements ApiVersionDeprecati
|
||||
|
||||
@Override
|
||||
public void handleVersion(
|
||||
Comparable<?> requestVersion, HttpServletRequest request, HttpServletResponse response) {
|
||||
Comparable<?> requestVersion, Object handler,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
for (VersionInfo info : this.infos.values()) {
|
||||
if (info.match(requestVersion, request)) {
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ public class StandardApiVersionDeprecationHandlerTests {
|
||||
.setSunsetDate(getDate(sunsetDate))
|
||||
.setSunsetLink(URI.create(sunsetUrl));
|
||||
|
||||
handler.handleVersion("1.1", request, response);
|
||||
handler.handleVersion("1.1", new Object(), request, response);
|
||||
|
||||
assertThat(response.getHeader("Deprecation")).isEqualTo("@1688169599");
|
||||
assertThat(response.getHeader("Sunset")).isEqualTo(sunsetDate);
|
||||
|
||||
+2
-1
@@ -33,8 +33,9 @@ public interface ApiVersionDeprecationHandler {
|
||||
* accordingly, e.g. by setting response headers to signal the deprecation,
|
||||
* to specify relevant dates and provide links to further details.
|
||||
* @param version the resolved and parsed request version
|
||||
* @param handler the handler chosen for the exchange
|
||||
* @param exchange the current exchange
|
||||
*/
|
||||
void handleVersion(Comparable<?> version, ServerWebExchange exchange);
|
||||
void handleVersion(Comparable<?> version, Object handler, ServerWebExchange exchange);
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -93,9 +93,10 @@ public interface ApiVersionStrategy {
|
||||
* accordingly, e.g. by setting response headers to signal the deprecation,
|
||||
* to specify relevant dates and provide links to further details.
|
||||
* @param version the resolved and parsed request version
|
||||
* @param handler the handler chosen for the exchange
|
||||
* @param exchange the current exchange
|
||||
* @see ApiVersionDeprecationHandler
|
||||
*/
|
||||
void handleDeprecations(Comparable<?> version, ServerWebExchange exchange);
|
||||
void handleDeprecations(Comparable<?> version, Object handler, ServerWebExchange exchange);
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -181,9 +181,9 @@ public class DefaultApiVersionStrategy implements ApiVersionStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDeprecations(Comparable<?> version, ServerWebExchange exchange) {
|
||||
public void handleDeprecations(Comparable<?> version, Object handler, ServerWebExchange exchange) {
|
||||
if (this.deprecationHandler != null) {
|
||||
this.deprecationHandler.handleVersion(version, exchange);
|
||||
this.deprecationHandler.handleVersion(version, handler, exchange);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class StandardApiVersionDeprecationHandler implements ApiVersionDeprecati
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleVersion(Comparable<?> requestVersion, ServerWebExchange exchange) {
|
||||
public void handleVersion(Comparable<?> requestVersion, Object handler, ServerWebExchange exchange) {
|
||||
for (VersionInfo info : this.infos.values()) {
|
||||
if (info.match(requestVersion, exchange)) {
|
||||
HttpHeaders headers = exchange.getResponse().getHeaders();
|
||||
|
||||
+1
-1
@@ -206,7 +206,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
|
||||
if (getApiVersionStrategy() != null) {
|
||||
Comparable<?> version = exchange.getAttribute(API_VERSION_ATTRIBUTE);
|
||||
if (version != null) {
|
||||
getApiVersionStrategy().handleDeprecations(version, exchange);
|
||||
getApiVersionStrategy().handleDeprecations(version, handler, exchange);
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class StandardApiVersionDeprecationHandlerTests {
|
||||
.setSunsetDate(getDate(sunsetDate))
|
||||
.setSunsetLink(URI.create(sunsetUrl));
|
||||
|
||||
handler.handleVersion("1.1", exchange);
|
||||
handler.handleVersion("1.1", handler, exchange);
|
||||
|
||||
HttpHeaders headers = exchange.getResponse().getHeaders();
|
||||
assertThat(headers.getFirst("Deprecation")).isEqualTo("@1688169599");
|
||||
|
||||
+1
-1
@@ -803,7 +803,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
this.versionStrategy.handleDeprecations(this.version, request, response);
|
||||
this.versionStrategy.handleDeprecations(this.version, handler, request, response);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user