Return null from MockServletContext.getMimeType for unknown type
ServletContext.getMimeType() returns `null` for unknown mime types; not `application/octet-stream`. Issue: SPR-14908
This commit is contained in:
parent
fd1db57e05
commit
e2aa880301
|
|
@ -50,6 +50,7 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.http.MediaTypeFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
|
@ -267,7 +268,9 @@ public class MockServletContext implements ServletContext {
|
|||
return this.mimeTypes.get(extension).toString();
|
||||
}
|
||||
else {
|
||||
return MediaTypeFactory.getMediaType(filePath).orElse(MediaType.APPLICATION_OCTET_STREAM).toString();
|
||||
return MediaTypeFactory.getMediaType(filePath).
|
||||
map(MimeType::toString)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ public class MockServletContextTests {
|
|||
public void getMimeType() {
|
||||
assertEquals("text/html", sc.getMimeType("test.html"));
|
||||
assertEquals("image/gif", sc.getMimeType("test.gif"));
|
||||
assertNull(sc.getMimeType("test.foobar"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.http.MediaTypeFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
|
@ -266,7 +267,9 @@ public class MockServletContext implements ServletContext {
|
|||
return this.mimeTypes.get(extension).toString();
|
||||
}
|
||||
else {
|
||||
return MediaTypeFactory.getMediaType(filePath).orElse(MediaType.APPLICATION_OCTET_STREAM).toString();
|
||||
return MediaTypeFactory.getMediaType(filePath).
|
||||
map(MimeType::toString)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue