mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix check bug
This commit is contained in:
parent
c008d0a081
commit
a114113be0
@ -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)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,19 @@ public enum Header {
|
||||
|
||||
//------------------------------------------------------------- 通用头域
|
||||
/**
|
||||
* 提供验证头
|
||||
* 提供验证头,例如:
|
||||
* <pre>
|
||||
* Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*/
|
||||
AUTHORIZATION("Authorization"),
|
||||
/**
|
||||
* 提供给代理服务器的用于身份验证的凭证,例如:
|
||||
* <pre>
|
||||
* Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*/
|
||||
PROXY_AUTHORIZATION("Proxy-Authorization"),
|
||||
/**
|
||||
* 提供日期和时间标志,说明报文是什么时间创建的
|
||||
*/
|
||||
|
@ -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<HttpRequest> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单验证
|
||||
* 简单验证,生成的头信息类似于:
|
||||
* <pre>
|
||||
* Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单代理验证,生成的头信息类似于:
|
||||
* <pre>
|
||||
* Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*
|
||||
* @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<HttpRequest> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证,简单插入Authorization头
|
||||
*
|
||||
* @param content 验证内容
|
||||
* @return HttpRequest
|
||||
* @since 5.4.6
|
||||
*/
|
||||
public HttpRequest proxyAuth(String content) {
|
||||
header(Header.PROXY_AUTHORIZATION, content, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = StrUtil.builder();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FastByteArrayOutputStream;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
@ -870,4 +871,21 @@ public class HttpUtil {
|
||||
public static SimpleServer createServer(int port) {
|
||||
return new SimpleServer(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建简单的账号秘密验证信息,构建后类似于:
|
||||
* <pre>
|
||||
* Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user