This commit is contained in:
Looly
2024-10-02 17:46:43 +08:00
parent 05d02bdb3c
commit 33a4746dc6
5 changed files with 14 additions and 8 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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));
}