From 72cdab49349541f0a78a09ad8c765ba8bd9989f1 Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Tue, 18 Dec 2012 13:09:21 +0100 Subject: [PATCH] 395794 slightly modified fix for empty file extenstion to mime type mapping. Added a default, so it will also work with unknown file extensions --- .../java/org/eclipse/jetty/http/MimeTypes.java | 2 +- .../org/eclipse/jetty/http/mime.properties | 1 + .../org/eclipse/jetty/http/MimeTypesTest.java | 15 +++++++++------ .../org/eclipse/jetty/server/ResourceCache.java | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java index 6e301f654b3..f1d6ca4c100 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java @@ -237,7 +237,7 @@ public class MimeTypes /** Set a mime mapping * @param extension * @param type - */ + */ public void addMimeMapping(String extension,String type) { _mimeMap.put(StringUtil.asciiToLowerCase(extension),normalizeMimeType(type)); diff --git a/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties b/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties index 74601e30851..52be4007dc6 100644 --- a/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties +++ b/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties @@ -1,3 +1,4 @@ +*=application/octet-stream ai=application/postscript aif=audio/x-aiff aifc=audio/x-aiff diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/MimeTypesTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/MimeTypesTest.java index 87073f00c60..069e12379c1 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/MimeTypesTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/MimeTypesTest.java @@ -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) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java index 3f1f86ef17e..48026eaf943 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java @@ -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));