Merge branch '5.1.x'

This commit is contained in:
Rossen Stoyanchev
2019-05-01 04:03:21 -04:00
5 changed files with 56 additions and 5 deletions

View File

@@ -188,9 +188,12 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
@Override
@Nullable
public ProducesRequestCondition getMatchingCondition(ServerWebExchange exchange) {
if (isEmpty() || CorsUtils.isPreFlightRequest(exchange.getRequest())) {
if (CorsUtils.isPreFlightRequest(exchange.getRequest())) {
return EMPTY_CONDITION;
}
if (isEmpty()) {
return this;
}
List<ProduceMediaTypeExpression> result = getMatchingExpressions(exchange);
if (!CollectionUtils.isEmpty(result)) {
return new ProducesRequestCondition(result, this);

View File

@@ -21,7 +21,10 @@ import java.util.Collections;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.*;
@@ -129,6 +132,23 @@ public class ProducesRequestConditionTests {
assertNotNull(condition.getMatchingCondition(exchange));
}
@Test // gh-22853
public void matchAndCompare() {
RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
builder.headerResolver();
builder.fixedResolver(MediaType.TEXT_HTML);
RequestedContentTypeResolver resolver = builder.build();
ProducesRequestCondition none = new ProducesRequestCondition(new String[0], null, resolver);
ProducesRequestCondition html = new ProducesRequestCondition(new String[] {"text/html"}, null, resolver);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "*/*"));
ProducesRequestCondition noneMatch = none.getMatchingCondition(exchange);
ProducesRequestCondition htmlMatch = html.getMatchingCondition(exchange);
assertEquals(1, noneMatch.compareTo(htmlMatch, exchange));
}
@Test
public void compareTo() {