Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -77,7 +76,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the underlying conditions, possibly empty but never {@code null}.
|
||||
* Return the underlying conditions (possibly empty but never {@code null}).
|
||||
*/
|
||||
public List<RequestCondition<?>> getConditions() {
|
||||
return unwrap();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.condition;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -49,7 +48,6 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
|
||||
|
||||
private final static ConsumesRequestCondition PRE_FLIGHT_MATCH = new ConsumesRequestCondition();
|
||||
|
||||
|
||||
private final List<ConsumeMediaTypeExpression> expressions;
|
||||
|
||||
|
||||
@@ -159,7 +157,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
|
||||
* @param request the current request
|
||||
* @return the same instance if the condition contains no expressions;
|
||||
* or a new condition with matching expressions only;
|
||||
* or {@code null} if no expressions match.
|
||||
* or {@code null} if no expressions match
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
@@ -170,23 +168,20 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
|
||||
if (isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
MediaType contentType;
|
||||
try {
|
||||
contentType = StringUtils.hasLength(request.getContentType()) ?
|
||||
contentType = (StringUtils.hasLength(request.getContentType()) ?
|
||||
MediaType.parseMediaType(request.getContentType()) :
|
||||
MediaType.APPLICATION_OCTET_STREAM;
|
||||
MediaType.APPLICATION_OCTET_STREAM);
|
||||
}
|
||||
catch (InvalidMediaTypeException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
|
||||
for (Iterator<ConsumeMediaTypeExpression> iterator = result.iterator(); iterator.hasNext();) {
|
||||
ConsumeMediaTypeExpression expression = iterator.next();
|
||||
if (!expression.match(contentType)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return (result.isEmpty()) ? null : new ConsumesRequestCondition(result);
|
||||
result.removeIf(expression -> !expression.match(contentType));
|
||||
return (!result.isEmpty() ? new ConsumesRequestCondition(result) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.condition;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -48,14 +47,14 @@ import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition.Hea
|
||||
*/
|
||||
public final class ProducesRequestCondition extends AbstractRequestCondition<ProducesRequestCondition> {
|
||||
|
||||
private final static ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
|
||||
private static final ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
|
||||
|
||||
private static final ProducesRequestCondition EMPTY_CONDITION = new ProducesRequestCondition();
|
||||
|
||||
|
||||
private static final List<ProduceMediaTypeExpression> MEDIA_TYPE_ALL_LIST =
|
||||
Collections.singletonList(new ProduceMediaTypeExpression("*/*"));
|
||||
|
||||
|
||||
private final List<ProduceMediaTypeExpression> expressions;
|
||||
|
||||
private final ContentNegotiationManager contentNegotiationManager;
|
||||
@@ -194,6 +193,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
|
||||
if (isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
List<MediaType> acceptedMediaTypes;
|
||||
try {
|
||||
acceptedMediaTypes = getAcceptedMediaTypes(request);
|
||||
@@ -201,13 +201,9 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
|
||||
catch (HttpMediaTypeException ex) {
|
||||
return null;
|
||||
}
|
||||
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(expressions);
|
||||
for (Iterator<ProduceMediaTypeExpression> iterator = result.iterator(); iterator.hasNext();) {
|
||||
ProduceMediaTypeExpression expression = iterator.next();
|
||||
if (!expression.match(acceptedMediaTypes)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
|
||||
result.removeIf(expression -> !expression.match(acceptedMediaTypes));
|
||||
if (!result.isEmpty()) {
|
||||
return new ProducesRequestCondition(result, this.contentNegotiationManager);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user