mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -107,7 +107,7 @@ public class JdkClientEngine extends AbstractClientEngine {
|
||||
|
||||
@Override
|
||||
protected void initEngine() {
|
||||
this.cookieManager = this.config.isUseCookieManager() ? new JdkCookieManager() : new JdkCookieManager(null);
|
||||
this.cookieManager = (null != this.config && this.config.isUseCookieManager()) ? new JdkCookieManager() : new JdkCookieManager(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +160,8 @@ public class JdkClientEngine extends AbstractClientEngine {
|
||||
}
|
||||
}
|
||||
|
||||
if (null == message.header(HeaderName.COOKIE)) {
|
||||
// Cookie管理
|
||||
if (null == message.header(HeaderName.COOKIE) && null != this.cookieManager) {
|
||||
// 用户没有自定义Cookie,则读取Cookie管理器中的信息并附带到请求中
|
||||
// 不覆盖模式回填Cookie头,这样用户定义的Cookie将优先
|
||||
conn.header(this.cookieManager.loadForRequest(conn), false);
|
||||
|
@@ -272,7 +272,9 @@ public class JdkHttpResponse implements Response, Closeable {
|
||||
}
|
||||
|
||||
// 存储服务端设置的Cookie信息
|
||||
this.cookieManager.saveFromResponse(this.httpConnection, this.headers);
|
||||
if(null != this.cookieManager){
|
||||
this.cookieManager.saveFromResponse(this.httpConnection, this.headers);
|
||||
}
|
||||
|
||||
// 获取响应内容流
|
||||
if (!isIgnoreBody) {
|
||||
|
@@ -135,7 +135,7 @@ public class OkHttpEngine extends AbstractClientEngine {
|
||||
setProxy(builder, config);
|
||||
|
||||
// Cookie管理
|
||||
if (this.config.isUseCookieManager()) {
|
||||
if (null != this.config && this.config.isUseCookieManager()) {
|
||||
this.cookieStore = new InMemoryCookieStore();
|
||||
builder.cookieJar(new CookieJarImpl(this.cookieStore));
|
||||
}
|
||||
|
Reference in New Issue
Block a user