mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix bug #1341
This commit is contained in:
parent
99934e2b9f
commit
b8e5cc006e
@ -12,6 +12,7 @@
|
||||
* 【core 】 修复ZipUtil.unzip从流解压关闭问题(issue#I2B0S1@Gitee)
|
||||
* 【poi 】 修复Excel07Writer写出表格错乱问题(issue#I2B57B@Gitee)
|
||||
* 【poi 】 修复SheetRidReader读取字段错误问题(issue#1342@Github)
|
||||
* 【core 】 修复FileUtil.getMimeType不支持css和js(issue#1341@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -3182,7 +3182,16 @@ public class FileUtil extends PathUtil {
|
||||
* @since 4.1.15
|
||||
*/
|
||||
public static String getMimeType(String filePath) {
|
||||
return URLConnection.getFileNameMap().getContentTypeFor(filePath);
|
||||
String contentType = URLConnection.getFileNameMap().getContentTypeFor(filePath);
|
||||
if(null == contentType){
|
||||
// 补充一些常用的mimeType
|
||||
if(filePath.endsWith(".css")){
|
||||
contentType = "text/css";
|
||||
} else if(filePath.endsWith(".js")){
|
||||
contentType = "application/x-javascript";
|
||||
}
|
||||
}
|
||||
return contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -376,6 +376,12 @@ public class FileUtilTest {
|
||||
public void getMimeTypeTest() {
|
||||
String mimeType = FileUtil.getMimeType("test2Write.jpg");
|
||||
Assert.assertEquals("image/jpeg", mimeType);
|
||||
|
||||
mimeType = FileUtil.getMimeType("main.css");
|
||||
Assert.assertEquals("text/css", mimeType);
|
||||
|
||||
mimeType = FileUtil.getMimeType("test.js");
|
||||
Assert.assertEquals("application/x-javascript", mimeType);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2,7 +2,6 @@ package cn.hutool.http.server.action;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.server.HttpServerRequest;
|
||||
import cn.hutool.http.server.HttpServerResponse;
|
||||
|
||||
@ -80,7 +79,6 @@ public class RootAction implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
Console.log(file.getAbsolutePath());
|
||||
response.send404("404 Not Found !");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* {@link com.sun.net.httpserver.HttpServer} 封装
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
package cn.hutool.http.server.action;
|
Loading…
Reference in New Issue
Block a user