diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a908b27..579fb5573 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,14 @@ ------------------------------------------------------------------------------------------------------------- -# 5.4.6 (2020-10-18) +# 5.4.6 (2020-10-21) ### 新特性 +* 【http 】 HttpRequest增加basicProxyAuth方法(issue#I1YQGM@Gitee) + ### Bug修复 +* 【core 】 修复ChineseDate没有忽略时分秒导致计算错误问题(issue#I1YW12@Gitee) +* 【core 】 修复FileUtil中,copyFile方法断言判断参数传递错误(issue#I1Z2NY@Gitee) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java b/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java index e29679925..e6166d318 100644 --- a/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java +++ b/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java @@ -48,7 +48,7 @@ public class ChineseDate { */ public ChineseDate(Date date) { // 求出和1900年1月31日相差的天数 - int offset = (int) ((date.getTime() / DateUnit.DAY.getMillis()) - BASE_DAY); + int offset = (int) ((DateUtil.beginOfDay(date).getTime() / DateUnit.DAY.getMillis()) - BASE_DAY); // 计算农历年份 // 用offset减去每农历年的天数,计算当天是农历第几天,offset是当年的第几天 int daysOfYear; diff --git a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java index 6b3db398a..f7a76de1d 100644 --- a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java @@ -862,7 +862,7 @@ public class FileUtil extends PathUtil { */ public static File copyFile(String src, String dest, StandardCopyOption... options) throws IORuntimeException { Assert.notBlank(src, "Source File path is blank !"); - Assert.notNull(src, "Destination File path is null !"); + Assert.notBlank(dest, "Destination File path is blank !"); return copyFile(Paths.get(src), Paths.get(dest), options).toFile(); } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java b/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java index 2394cfa50..1792fd4ff 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java @@ -95,4 +95,10 @@ public class ChineseDateTest { date = new ChineseDate(DateUtil.parseDate("1991-09-15")); Assert.assertEquals("辛未羊年 八月初八", date.toString()); } + + @Test + public void dateTest2(){ + ChineseDate date = new ChineseDate(DateUtil.parse("2020-10-19 11:12:23")); + Assert.assertEquals("庚子鼠年 九月初三", date.toString()); + } } diff --git a/hutool-http/src/main/java/cn/hutool/http/Header.java b/hutool-http/src/main/java/cn/hutool/http/Header.java index 1c90606c5..86dc86245 100644 --- a/hutool-http/src/main/java/cn/hutool/http/Header.java +++ b/hutool-http/src/main/java/cn/hutool/http/Header.java @@ -9,9 +9,19 @@ public enum Header { //------------------------------------------------------------- 通用头域 /** - * 提供验证头 + * 提供验证头,例如: + *
+ * Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l + **/ AUTHORIZATION("Authorization"), + /** + * 提供给代理服务器的用于身份验证的凭证,例如: + *
+ * Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l + *+ */ + PROXY_AUTHORIZATION("Proxy-Authorization"), /** * 提供日期和时间标志,说明报文是什么时间创建的 */ diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java index b0cae62d8..daba627c1 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java @@ -1,6 +1,5 @@ package cn.hutool.http; -import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.io.IORuntimeException; @@ -981,16 +980,32 @@ public class HttpRequest extends HttpBase
+ * Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l + ** * @param username 用户名 * @param password 密码 - * @return HttpRequest + * @return this */ public HttpRequest basicAuth(String username, String password) { - final String data = username.concat(":").concat(password); - final String base64 = Base64.encode(data, charset); - return auth("Basic " + base64); + return auth(HttpUtil.buildBasicAuth(username, password, charset)); + } + + /** + * 简单代理验证,生成的头信息类似于: + *
+ * Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l + *+ * + * @param username 用户名 + * @param password 密码 + * @return this + * @since 5.4.6 + */ + public HttpRequest basicProxyAuth(String username, String password) { + return proxyAuth(HttpUtil.buildBasicAuth(username, password, charset)); } /** @@ -1005,6 +1020,18 @@ public class HttpRequest extends HttpBase
+ * Basic YWxhZGRpbjpvcGVuc2VzYW1l + *+ * + * @param username 账号 + * @param password 密码 + * @param charset 编码(如果账号或密码中有非ASCII字符适用) + * @return 密码验证信息 + * @since 5.4.6 + */ + public static String buildBasicAuth(String username, String password, Charset charset){ + final String data = username.concat(":").concat(password); + return "Basic " + Base64.encode(data, charset); + } }