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 d0c8cd17733..87073f00c60 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 @@ -20,6 +20,7 @@ package org.eclipse.jetty.http; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Test; @@ -57,6 +58,14 @@ public class MimeTypesTest assertMimeTypeByExtension("text/plain","test.txt"); assertMimeTypeByExtension("text/plain","TEST.TXT"); } + + @Test + public void testGetMimeByExtension_NoExtension() + { + MimeTypes mimetypes = new MimeTypes(); + String contentType = mimetypes.getMimeByExtension("README"); + assertNull(contentType); + } 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 c0206b44793..3f1f86ef17e 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 @@ -382,7 +382,8 @@ public class ResourceCache _key=pathInContext; _resource=resource; - _contentType=BufferUtil.toBuffer(_mimeTypes.getMimeByExtension(_resource.toString())); + String mimeType = _mimeTypes.getMimeByExtension(_resource.toString()); + _contentType=(mimeType==null?null:BufferUtil.toBuffer(mimeType)); boolean exists=resource.exists(); _lastModified=exists?resource.lastModified():-1; _lastModifiedBytes=_lastModified<0?null:BufferUtil.toBuffer(HttpFields.formatDate(_lastModified)); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java index b1cc1e45b3f..16d9c24356e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java @@ -229,6 +229,23 @@ public class ResourceCacheTest cache.flushCache(); } + @Test + public void testNoextension() throws Exception + { + ResourceCollection rc = new ResourceCollection(new String[]{ + "../jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/" + }); + + Resource[] resources = rc.getResources(); + MimeTypes mime = new MimeTypes(); + + ResourceCache cache = new ResourceCache(null,resources[0],mime,false,false); + + assertEquals("4 - four", getContent(cache, "four.txt")); + assertEquals("4 - four (no extension)", getContent(cache, "four")); + } + + static String getContent(Resource r, String path) throws Exception { StringBuilder buffer = new StringBuilder(); diff --git a/jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/four b/jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/four new file mode 100644 index 00000000000..02bf84b552d --- /dev/null +++ b/jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/four @@ -0,0 +1 @@ +4 - four (no extension) \ No newline at end of file diff --git a/jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/four.txt b/jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/four.txt new file mode 100644 index 00000000000..05a6c6fbc8d --- /dev/null +++ b/jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/four.txt @@ -0,0 +1 @@ +4 - four \ No newline at end of file