mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
470168e11b
commit
e58c8c9d6c
@ -24,6 +24,7 @@
|
|||||||
* 【core 】 CollUtil增加safeContains方法(pr#1926@Github)
|
* 【core 】 CollUtil增加safeContains方法(pr#1926@Github)
|
||||||
* 【core 】 ActualTypeMapperPool增加getStrKeyMap方法(pr#447@Gitee)
|
* 【core 】 ActualTypeMapperPool增加getStrKeyMap方法(pr#447@Gitee)
|
||||||
* 【core 】 TreeUtil增加walk方法(pr#1932@Gitee)
|
* 【core 】 TreeUtil增加walk方法(pr#1932@Gitee)
|
||||||
|
* 【crypto 】 SmUtil增加sm3WithSalt(pr#454@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
|
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
|
||||||
|
@ -54,7 +54,7 @@ public class SmUtil {
|
|||||||
public static final ECDomainParameters SM2_DOMAIN_PARAMS = BCUtil.toDomainParams(GMNamedCurves.getByName(SM2_CURVE_NAME));
|
public static final ECDomainParameters SM2_DOMAIN_PARAMS = BCUtil.toDomainParams(GMNamedCurves.getByName(SM2_CURVE_NAME));
|
||||||
/**
|
/**
|
||||||
* SM2国密算法公钥参数的Oid标识
|
* SM2国密算法公钥参数的Oid标识
|
||||||
*/
|
*/
|
||||||
public static final ASN1ObjectIdentifier ID_SM2_PUBLIC_KEY_PARAM = new ASN1ObjectIdentifier("1.2.156.10197.1.301");
|
public static final ASN1ObjectIdentifier ID_SM2_PUBLIC_KEY_PARAM = new ASN1ObjectIdentifier("1.2.156.10197.1.301");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,12 +134,13 @@ public class SmUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SM3加密,可以传入盐<br>
|
* SM3加密,可以传入盐
|
||||||
*
|
*
|
||||||
* @param salt 加密盐
|
* @param salt 加密盐
|
||||||
* @return {@link SM3}
|
* @return {@link SM3}
|
||||||
|
* @since 5.7.16
|
||||||
*/
|
*/
|
||||||
public static SM3 sm3(byte[] salt) {
|
public static SM3 sm3WithSalt(byte[] salt) {
|
||||||
return new SM3(salt);
|
return new SM3(salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +147,11 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
*/
|
*/
|
||||||
private SSLSocketFactory ssf;
|
private SSLSocketFactory ssf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求前的处理器,用于在请求前重新编辑请求,类似于拦截器
|
||||||
|
*/
|
||||||
|
private Consumer<HttpRequest> consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造,URL编码默认使用UTF-8
|
* 构造,URL编码默认使用UTF-8
|
||||||
*
|
*
|
||||||
@ -919,6 +924,16 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置请求前的处理器,用于在请求前重新编辑请求,类似于拦截器
|
||||||
|
*
|
||||||
|
* @param consumer 请求前的处理器,用于在请求前重新编辑请求,类似于拦截器
|
||||||
|
* @since 5.7.16
|
||||||
|
*/
|
||||||
|
public void setConsumer(Consumer<HttpRequest> consumer) {
|
||||||
|
this.consumer = consumer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行Reuqest请求
|
* 执行Reuqest请求
|
||||||
*
|
*
|
||||||
@ -949,22 +964,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public HttpResponse execute(boolean isAsync) {
|
public HttpResponse execute(boolean isAsync) {
|
||||||
// 初始化URL
|
return doExecute(isAsync, this.consumer);
|
||||||
urlWithParamIfGet();
|
|
||||||
// 初始化 connection
|
|
||||||
initConnection();
|
|
||||||
// 发送请求
|
|
||||||
send();
|
|
||||||
|
|
||||||
// 手动实现重定向
|
|
||||||
HttpResponse httpResponse = sendRedirectIfPossible();
|
|
||||||
|
|
||||||
// 获取响应
|
|
||||||
if (null == httpResponse) {
|
|
||||||
httpResponse = new HttpResponse(this.httpConnection, this.charset, isAsync, isIgnoreResponseBody());
|
|
||||||
}
|
|
||||||
|
|
||||||
return httpResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1054,6 +1054,35 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
|
|
||||||
// ---------------------------------------------------------------- Private method start
|
// ---------------------------------------------------------------- Private method start
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行Reuqest请求
|
||||||
|
*
|
||||||
|
* @param isAsync 是否异步
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
private HttpResponse doExecute(boolean isAsync, Consumer<HttpRequest> consumer) {
|
||||||
|
if (null != consumer) {
|
||||||
|
consumer.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化URL
|
||||||
|
urlWithParamIfGet();
|
||||||
|
// 初始化 connection
|
||||||
|
initConnection();
|
||||||
|
// 发送请求
|
||||||
|
send();
|
||||||
|
|
||||||
|
// 手动实现重定向
|
||||||
|
HttpResponse httpResponse = sendRedirectIfPossible(isAsync);
|
||||||
|
|
||||||
|
// 获取响应
|
||||||
|
if (null == httpResponse) {
|
||||||
|
httpResponse = new HttpResponse(this.httpConnection, this.charset, isAsync, isIgnoreResponseBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpResponse;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化网络连接
|
* 初始化网络连接
|
||||||
*/
|
*/
|
||||||
@ -1108,9 +1137,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
/**
|
/**
|
||||||
* 调用转发,如果需要转发返回转发结果,否则返回{@code null}
|
* 调用转发,如果需要转发返回转发结果,否则返回{@code null}
|
||||||
*
|
*
|
||||||
|
* @param isAsync 是否异步
|
||||||
* @return {@link HttpResponse},无转发返回 {@code null}
|
* @return {@link HttpResponse},无转发返回 {@code null}
|
||||||
*/
|
*/
|
||||||
private HttpResponse sendRedirectIfPossible() {
|
private HttpResponse sendRedirectIfPossible(boolean isAsync) {
|
||||||
if (this.maxRedirectCount < 1) {
|
if (this.maxRedirectCount < 1) {
|
||||||
// 不重定向
|
// 不重定向
|
||||||
return null;
|
return null;
|
||||||
@ -1132,7 +1162,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
setUrl(httpConnection.header(Header.LOCATION));
|
setUrl(httpConnection.header(Header.LOCATION));
|
||||||
if (redirectCount < this.maxRedirectCount) {
|
if (redirectCount < this.maxRedirectCount) {
|
||||||
redirectCount++;
|
redirectCount++;
|
||||||
return execute();
|
return doExecute(isAsync, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user