add Handler

This commit is contained in:
Looly
2020-04-02 10:21:21 +08:00
parent c7ce3719e8
commit b2201873ea
8 changed files with 201 additions and 44 deletions

View File

@@ -0,0 +1,13 @@
package cn.hutool.http.server;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.server.handler.RootHandler;
public class SimpleServerTest {
public static void main(String[] args) {
HttpUtil.createServer(8888)
.addHandler("/", new RootHandler("D:\\test"))
.start();
}
}

View File

@@ -1,21 +0,0 @@
package cn.hutool.http.test;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import cn.hutool.http.server.SimpleServer;
import java.io.OutputStream;
public class SimpleServerTest {
public static void main(String[] args) {
final SimpleServer server = new SimpleServer(8888);
server.addHandler("/", httpExchange -> {
httpExchange.sendResponseHeaders(HttpStatus.HTTP_OK, 0);
final OutputStream out = httpExchange.getResponseBody();
out.write(StrUtil.bytes("Hello Hutool Server!"));
IoUtil.close(out);
}).start();
}
}