Skip to content

Commit

Permalink
fix: RSAAutoCertificateProvider 构造时使用的参数做防御性复制
Browse files Browse the repository at this point in the history
  • Loading branch information
xy-peng committed Feb 6, 2023
1 parent c0e6c35 commit 16823e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public Builder merchantSerialNumber(String merchantSerialNumber) {
}

public Builder httpClientBuilder(AbstractHttpClientBuilder<?> builder) {
this.httpClientBuilder = builder;
// httpClientBuilder 不是不可变的,所以为了避免过程中修改入参或者值发生变化,这里制作了一个副本
this.httpClientBuilder = builder.newInstance();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@

public interface AbstractHttpClientBuilder<T extends AbstractHttpClientBuilder<T>> {

/**
* 复制工厂,复制一个当前对象
*
* @return 对象的副本
*/
T newInstance();

/**
* 设置验证器
*
* @param validator 验证器
* @return T the AbstractHttpClientBuilder
* @return the AbstractHttpClientBuilder
*/
T validator(Validator validator);

/**
* 设置凭据生成器
*
* @param credential 凭据生成器
* @return T the AbstractHttpClientBuilder
* @return the AbstractHttpClientBuilder
*/
T credential(Credential credential);

/**
* * 构建 AbstractHttpClient
* 构建 AbstractHttpClient
*
* @return AbstractHttpClient
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ public class DefaultHttpClientBuilder
private int connectTimeoutMs = -1;
private Proxy proxy;

/**
* 复制工厂,复制一个当前对象
*
* @return 对象的副本
*/
@Override
public DefaultHttpClientBuilder newInstance() {
DefaultHttpClientBuilder result = new DefaultHttpClientBuilder();
result.credential = this.credential;
result.validator = this.validator;
result.customizeOkHttpClient = this.customizeOkHttpClient;
result.readTimeoutMs = this.readTimeoutMs;
result.writeTimeoutMs = this.writeTimeoutMs;
result.connectTimeoutMs = this.connectTimeoutMs;
result.proxy = this.proxy;
return result;
}

/**
* 设置读超时
*
Expand Down

0 comments on commit 16823e7

Please sign in to comment.