Change MediaTypeFactory to return Optional
This commit changes the `MediaTypeFactory` to return `Optional<MediaType>` (instead of a plain `MediaType`) for the `getMediaType` methods. Issue: SPR-14908
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.web.reactive.accept;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -79,9 +80,9 @@ public class PathExtensionContentTypeResolver extends AbstractMappingContentType
|
||||
|
||||
@Override
|
||||
protected MediaType handleNoMatch(String key) throws NotAcceptableStatusException {
|
||||
MediaType mediaType = MediaTypeFactory.getMediaType("file." + key);
|
||||
if (mediaType != null) {
|
||||
return mediaType;
|
||||
Optional<MediaType> mediaType = MediaTypeFactory.getMediaType("file." + key);
|
||||
if (mediaType.isPresent()) {
|
||||
return mediaType.get();
|
||||
}
|
||||
if (!this.ignoreUnknownExtensions) {
|
||||
throw new NotAcceptableStatusException(getAllMediaTypes());
|
||||
@@ -105,7 +106,7 @@ public class PathExtensionContentTypeResolver extends AbstractMappingContentType
|
||||
mediaType = getMediaType(extension);
|
||||
}
|
||||
if (mediaType == null) {
|
||||
mediaType = MediaTypeFactory.getMediaType(filename);
|
||||
mediaType = MediaTypeFactory.getMediaType(filename).orElse(null);
|
||||
}
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user