Explicit HEAD sorted higher than implicit one

Same fix as #7cdcc1 but for WebFlux.

Issue: SPR-14182
This commit is contained in:
Rossen Stoyanchev
2019-01-02 09:23:05 -05:00
parent 72fbbb2403
commit 1cb9f2c7b2
3 changed files with 28 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -39,8 +39,8 @@ import org.springframework.web.server.ServerWebExchange;
*/
public final class RequestMethodsRequestCondition extends AbstractRequestCondition<RequestMethodsRequestCondition> {
private static final RequestMethodsRequestCondition HEAD_CONDITION =
new RequestMethodsRequestCondition(RequestMethod.HEAD);
private static final RequestMethodsRequestCondition GET_CONDITION =
new RequestMethodsRequestCondition(RequestMethod.GET);
private final Set<RequestMethod> methods;
@@ -139,7 +139,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
}
}
if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
return HEAD_CONDITION;
return GET_CONDITION;
}
}
return null;
@@ -158,7 +158,18 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
*/
@Override
public int compareTo(RequestMethodsRequestCondition other, ServerWebExchange exchange) {
return (other.methods.size() - this.methods.size());
if (other.methods.size() != this.methods.size()) {
return other.methods.size() - this.methods.size();
}
else if (this.methods.size() == 1) {
if (this.methods.contains(RequestMethod.HEAD) && other.methods.contains(RequestMethod.GET)) {
return -1;
}
else if (this.methods.contains(RequestMethod.GET) && other.methods.contains(RequestMethod.HEAD)) {
return 1;
}
}
return 0;
}
}