395794 slightly modified fix for empty file extenstion to mime type mapping. Added a default, so it will also work with unknown file extensions

This commit is contained in:
Thomas Becker 2012-12-18 13:09:21 +01:00
parent 58dff061e1
commit 72cdab4934
4 changed files with 12 additions and 8 deletions

View File

@ -1,3 +1,4 @@
*=application/octet-stream
ai=application/postscript
aif=audio/x-aiff
aifc=audio/x-aiff

View File

@ -18,11 +18,10 @@
package org.eclipse.jetty.http;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
public class MimeTypesTest
{
@ -62,9 +61,13 @@ public class MimeTypesTest
@Test
public void testGetMimeByExtension_NoExtension()
{
MimeTypes mimetypes = new MimeTypes();
String contentType = mimetypes.getMimeByExtension("README");
assertNull(contentType);
assertMimeTypeByExtension("application/octet-stream", "README");
}
@Test
public void testGetMimeByExtensionWithoutExistingMimeMapping()
{
assertMimeTypeByExtension("application/octet-stream", "awesome-font.ttf");
}
private void assertMimeTypeByExtension(String expectedMimeType, String filename)

View File

@ -383,7 +383,7 @@ public class ResourceCache
_resource=resource;
String mimeType = _mimeTypes.getMimeByExtension(_resource.toString());
_contentType=(mimeType==null?null:BufferUtil.toBuffer(mimeType));
_contentType=BufferUtil.toBuffer(mimeType);
boolean exists=resource.exists();
_lastModified=exists?resource.lastModified():-1;
_lastModifiedBytes=_lastModified<0?null:BufferUtil.toBuffer(HttpFields.formatDate(_lastModified));