prepare 5.3.0

This commit is contained in:
Looly
2020-04-04 00:50:44 +08:00
parent 3921a568dd
commit 6b13cb5263
53 changed files with 619 additions and 331 deletions

View File

@@ -1,13 +1,23 @@
package cn.hutool.http.server;
import cn.hutool.http.ContentType;
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"))
// 设置默认根目录,
.setRoot("d:/test")
// 返回JSON数据测试
.addAction("/restTest", (request, response) ->
response.write("{\"id\": 1, \"msg\": \"OK\"}", ContentType.JSON.toString())
)
// 获取表单数据测试
// http://localhost:8888/formTest?a=1&a=2&b=3
.addAction("/formTest", (request, response) ->
response.write(request.getParams().toString(), ContentType.TEXT_PLAIN.toString())
)
.start();
}
}

View File

@@ -1,13 +1,5 @@
package cn.hutool.http.test;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
@@ -15,6 +7,13 @@ import cn.hutool.core.util.ReUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class HttpUtilTest {
@@ -164,6 +163,16 @@ public class HttpUtilTest {
paramsStr = "a=bbb&c=你好&哈喽&";
encode = HttpUtil.encodeParams(paramsStr, CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("a=bbb&c=%E4%BD%A0%E5%A5%BD&%E5%93%88%E5%96%BD=", encode);
// URL原样输出
paramsStr = "https://www.hutool.cn/";
encode = HttpUtil.encodeParams(paramsStr, CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals(paramsStr, encode);
// URL原样输出
paramsStr = "https://www.hutool.cn/?";
encode = HttpUtil.encodeParams(paramsStr, CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("https://www.hutool.cn/", encode);
}
@Test