File tree Expand file tree Collapse file tree 3 files changed +9
-2
lines changed
main/java/org/springframework/mock/web
test/java/org/springframework/mock/web
spring-web/src/test/java/org/springframework/mock/web/test Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 5050import org .springframework .http .MediaTypeFactory ;
5151import org .springframework .util .Assert ;
5252import org .springframework .util .ClassUtils ;
53+ import org .springframework .util .MimeType ;
5354import org .springframework .util .ObjectUtils ;
5455import org .springframework .util .StringUtils ;
5556import org .springframework .web .util .WebUtils ;
@@ -267,7 +268,9 @@ public String getMimeType(String filePath) {
267268 return this .mimeTypes .get (extension ).toString ();
268269 }
269270 else {
270- return MediaTypeFactory .getMediaType (filePath ).orElse (MediaType .APPLICATION_OCTET_STREAM ).toString ();
271+ return MediaTypeFactory .getMediaType (filePath ).
272+ map (MimeType ::toString )
273+ .orElse (null );
271274 }
272275 }
273276
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ public void registerContextAndGetContext() {
8282 public void getMimeType () {
8383 assertEquals ("text/html" , sc .getMimeType ("test.html" ));
8484 assertEquals ("image/gif" , sc .getMimeType ("test.gif" ));
85+ assertNull (sc .getMimeType ("test.foobar" ));
8586 }
8687
8788 /**
Original file line number Diff line number Diff line change 5050import org .springframework .http .MediaTypeFactory ;
5151import org .springframework .util .Assert ;
5252import org .springframework .util .ClassUtils ;
53+ import org .springframework .util .MimeType ;
5354import org .springframework .util .ObjectUtils ;
5455import org .springframework .util .StringUtils ;
5556import org .springframework .web .util .WebUtils ;
@@ -266,7 +267,9 @@ public String getMimeType(String filePath) {
266267 return this .mimeTypes .get (extension ).toString ();
267268 }
268269 else {
269- return MediaTypeFactory .getMediaType (filePath ).orElse (MediaType .APPLICATION_OCTET_STREAM ).toString ();
270+ return MediaTypeFactory .getMediaType (filePath ).
271+ map (MimeType ::toString )
272+ .orElse (null );
270273 }
271274 }
272275
You can’t perform that action at this time.
0 commit comments