add method

This commit is contained in:
Looly 2020-10-09 10:27:22 +08:00
parent c1b757fa60
commit ecedb5fd82
4 changed files with 24 additions and 6 deletions

View File

@ -3,10 +3,12 @@
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.4.5 (2020-09-30) # 5.4.5 (2020-10-09)
### 新特性 ### 新特性
* 【core 】 ConsoleTable代码优化pr#190@Gitee * 【core 】 ConsoleTable代码优化pr#190@Gitee
* 【http 】 HttpRequest增加setProxy重载pr#190@Gitee
* 【http 】 XmlUtil.cleanCommentpr#191@Gitee
### Bug修复 ### Bug修复

View File

@ -72,7 +72,7 @@ public class XmlUtil {
/** /**
* 在XML中注释的内容 正则 * 在XML中注释的内容 正则
*/ */
public static final String NOTE_REGEX = "(?s)<!--.+?-->"; public static final String COMMENT_REGEX = "(?s)<!--.+?-->";
/** /**
* XML格式化输出默认缩进量 * XML格式化输出默认缩进量
*/ */
@ -680,12 +680,13 @@ public class XmlUtil {
* *
* @param xmlContent XML文本 * @param xmlContent XML文本
* @return 当传入为null时返回null * @return 当传入为null时返回null
* @since 5.4.5
*/ */
public static String cleanNote(String xmlContent) { public static String cleanComment(String xmlContent) {
if (xmlContent == null) { if (xmlContent == null) {
return null; return null;
} }
return xmlContent.replaceAll(NOTE_REGEX, ""); return xmlContent.replaceAll(COMMENT_REGEX, StrUtil.EMPTY);
} }
/** /**

View File

@ -212,9 +212,9 @@ public class XmlUtilTest {
} }
@Test @Test
public void cleanNoteTest() { public void cleanCommentTest() {
final String xmlContent = "<info><title>hutool</title><!-- 这是注释 --><lang>java</lang></info>"; final String xmlContent = "<info><title>hutool</title><!-- 这是注释 --><lang>java</lang></info>";
final String ret = XmlUtil.cleanNote(xmlContent); final String ret = XmlUtil.cleanComment(xmlContent);
Assert.assertEquals("<info><title>hutool</title><lang>java</lang></info>", ret); Assert.assertEquals("<info><title>hutool</title><lang>java</lang></info>", ret);
} }

View File

@ -28,6 +28,7 @@ import java.io.OutputStream;
import java.net.CookieManager; import java.net.CookieManager;
import java.net.HttpCookie; import java.net.HttpCookie;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import java.net.URLStreamHandler; import java.net.URLStreamHandler;
import java.util.Collection; import java.util.Collection;
@ -841,6 +842,20 @@ public class HttpRequest extends HttpBase<HttpRequest> {
return this; return this;
} }
/**
* 设置Http代理
*
* @param host 代理 主机
* @param port 代理 端口
* @return this
* @since 5.4.5
*/
public HttpRequest setHttpProxy(String host, int port) {
final Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress(host, port));
return setProxy(proxy);
}
/** /**
* 设置代理 * 设置代理
* *