add filter

This commit is contained in:
Looly
2021-01-07 21:06:05 +08:00
parent c9a180abce
commit 0a768ad2c6
7 changed files with 165 additions and 11 deletions

View File

@@ -11,6 +11,10 @@ public class SimpleServerTest {
public static void main(String[] args) {
HttpUtil.createServer(8888)
.addFilter(((req, res, chain) -> {
Console.log("Filter: " + req.getPath());
chain.doFilter(req.getHttpExchange());
}))
// 设置默认根目录classpath/html
.setRoot(FileUtil.file("html"))
// get数据测试返回请求的PATH
@@ -46,7 +50,10 @@ public class SimpleServerTest {
}
)
// 测试输出响应内容是否能正常返回Content-Length头信息
.addAction("test/zeroStr", (req, res)-> res.write("0"))
.addAction("test/zeroStr", (req, res)-> {
res.write("0");
Console.log("Write 0 OK");
})
.start();
}
}