mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add method
This commit is contained in:
@@ -26,6 +26,7 @@ import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -296,6 +297,32 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
return this.httpExchange.getRequestBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定名称的参数值,取第一个值
|
||||
* @param name 参数名
|
||||
* @return 参数值
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public String getParam(String name){
|
||||
return getParams().get(name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定名称的参数值
|
||||
*
|
||||
* @param name 参数名
|
||||
* @return 参数值
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public List<String> getParams(String name){
|
||||
return getParams().get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数Map
|
||||
*
|
||||
* @return 参数map
|
||||
*/
|
||||
public ListValueMap<String, String> getParams() {
|
||||
if (null == this.paramsCache) {
|
||||
this.paramsCache = new ListValueMap<>();
|
||||
|
@@ -371,11 +371,25 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public HttpServerResponse write(File file) {
|
||||
return write(file, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件给客户端(文件下载)
|
||||
*
|
||||
* @param file 写出的文件对象
|
||||
* @return this
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public HttpServerResponse write(File file, String fileName) {
|
||||
final long fileSize = file.length();
|
||||
if(fileSize > Integer.MAX_VALUE){
|
||||
throw new IllegalArgumentException("File size is too bigger than " + Integer.MAX_VALUE);
|
||||
}
|
||||
final String fileName = file.getName();
|
||||
|
||||
if(StrUtil.isBlank(fileName)){
|
||||
fileName = file.getName();
|
||||
}
|
||||
final String contentType = ObjectUtil.defaultIfNull(HttpUtil.getMimeType(fileName), "application/octet-stream");
|
||||
BufferedInputStream in = null;
|
||||
try {
|
||||
|
@@ -64,6 +64,7 @@ public class RootAction implements Action {
|
||||
@Override
|
||||
public void doAction(HttpServerRequest request, HttpServerResponse response) {
|
||||
final String path = request.getPath();
|
||||
|
||||
File file = FileUtil.file(rootDir, path);
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
@@ -75,7 +76,8 @@ public class RootAction implements Action {
|
||||
}
|
||||
}
|
||||
} else{
|
||||
response.write(file);
|
||||
final String name = request.getParam("name");
|
||||
response.write(file, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user