mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复SimpleServer在添加的HttpFilter中有获取请求参数时报错问题
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package cn.hutool.http.server;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.multi.ListValueMap;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
||||
/**
|
||||
* http://localhost:8888/?name=hutool
|
||||
*/
|
||||
public class Issue3343Test {
|
||||
public static void main(final String[] args) {
|
||||
final SimpleServer server = HttpUtil.createServer(8888)
|
||||
.addFilter((req, res, chain) -> {
|
||||
Console.log(DateUtil.now() + " got request: " + req.getPath());
|
||||
Console.log(" > from : " + req.getClientIP());
|
||||
// 过滤器中获取请求参数
|
||||
Console.log(" > params : " + req.getParams());
|
||||
chain.doFilter(req.getHttpExchange());
|
||||
});
|
||||
|
||||
server.addAction("/", Issue3343Test::index);
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
private static void index(HttpServerRequest request, HttpServerResponse response) {
|
||||
// 具体逻辑中再次获取请求参数
|
||||
ListValueMap<String, String> params = request.getParams();
|
||||
Console.log("index params: " + params);
|
||||
response.getWriter().write("GOT: " + params);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user