Merge pull request #3550 from CNAHYZ/v6-dev

V6 dev 修改ClientEngineFactory中的部分有误注释,适配OkHttpEngine3.3.0至今的3.x版本
This commit is contained in:
Golden Looly 2024-04-17 09:22:44 +08:00 committed by GitHub
commit 123a276d17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 22 deletions

View File

@ -38,7 +38,7 @@ public class ClientEngineFactory {
}
/**
* 根据用户引入的HTTP客户端引擎jar自动创建对应的拼音引擎对象<br>
* 根据用户引入的HTTP客户端引擎jar自动创建对应的HTTP客户端引擎对象<br>
* 推荐创建的引擎单例使用此方法每次调用会返回新的引擎
*
* @param config Http客户端配置
@ -70,7 +70,7 @@ public class ClientEngineFactory {
}
/**
* 根据用户引入的HTTP客户端引擎jar自动创建对应的拼音引擎对象<br>
* 根据用户引入的HTTP客户端引擎jar自动创建对应的HTTP客户端引擎对象<br>
* 推荐创建的引擎单例使用此方法每次调用会返回新的引擎
*
* @return {@code ClientEngine}
@ -82,7 +82,7 @@ public class ClientEngineFactory {
}
/**
* 根据用户引入的拼音引擎jar自动创建对应的拼音引擎对象<br>
* 根据用户引入的HTTP客户端引擎jar自动创建对应的HTTP客户端引擎对象<br>
* 推荐创建的引擎单例使用此方法每次调用会返回新的引擎
*
* @return {@code EngineFactory}

View File

@ -85,31 +85,31 @@ public class OkHttpEngine implements ClientEngine {
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
final ClientConfig config = ObjUtil.defaultIfNull(this.config, ClientConfig::of);
final ClientConfig conf = ObjUtil.defaultIfNull(this.config, ClientConfig::of);
// 连接超时
final int connectionTimeout = config.getConnectionTimeout();
final int connectionTimeout = conf.getConnectionTimeout();
if (connectionTimeout > 0) {
builder.connectTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
}
// 读写超时
final int readTimeout = config.getReadTimeout();
final int readTimeout = conf.getReadTimeout();
if (readTimeout > 0) {
// 读写共用读取超时
builder.readTimeout(config.getReadTimeout(), TimeUnit.MILLISECONDS)
.writeTimeout(config.getReadTimeout(), TimeUnit.MILLISECONDS);
builder.readTimeout(conf.getReadTimeout(), TimeUnit.MILLISECONDS)
.writeTimeout(conf.getReadTimeout(), TimeUnit.MILLISECONDS);
}
// SSL
final SSLInfo sslInfo = config.getSslInfo();
if (null != sslInfo) {
final SSLInfo sslInfo = conf.getSslInfo();
if (null != sslInfo && null != sslInfo.getSocketFactory() && null != sslInfo.getTrustManager()){
builder.sslSocketFactory(sslInfo.getSocketFactory(), sslInfo.getTrustManager());
}
// 设置代理
setProxy(builder, config);
setProxy(builder, conf);
// 默认关闭自动跳转
builder.setFollowRedirects$okhttp(false);
builder.followRedirects(false);
this.client = builder.build();
}
@ -127,7 +127,6 @@ public class OkHttpEngine implements ClientEngine {
// 填充方法
final String method = message.method().name();
final HttpBody body = message.handledBody();
// if (HttpMethod.permitsRequestBody(method)) {
if (null != body) {
// 为了兼容支持rest请求在此不区分是否为GET等方法一律按照body是否有值填充兼容
builder.method(method, new OkHttpRequestBody(body));
@ -150,10 +149,10 @@ public class OkHttpEngine implements ClientEngine {
private static void setProxy(final OkHttpClient.Builder builder, final ClientConfig config) {
final HttpProxy proxy = config.getProxy();
if (null != proxy) {
builder.setProxy$okhttp(proxy);
builder.proxy(proxy);
final PasswordAuthentication auth = proxy.getAuth();
if (null != auth) {
builder.setProxyAuthenticator$okhttp(new BasicProxyAuthenticator(auth));
builder.proxyAuthenticator(new BasicProxyAuthenticator(auth));
}
}
}

View File

@ -60,13 +60,7 @@ public class OkHttpResponse implements Response {
@Override
public Map<String, List<String>> headers() {
final Headers headers = rawRes.headers();
final HashMap<String, List<String>> result = new LinkedHashMap<>(headers.size(), 1);
for (final Pair<? extends String, ? extends String> header : headers) {
final List<String> valueList = result.computeIfAbsent(header.getFirst(), k -> new ArrayList<>());
valueList.add(header.getSecond());
}
return result;
return rawRes.headers().toMultimap();
}
@Override