fix redirect

This commit is contained in:
Looly 2024-03-10 17:10:35 +08:00
parent b393d0d8f0
commit 868a0e6c3c
2 changed files with 8 additions and 8 deletions

View File

@ -42,10 +42,6 @@ import java.util.List;
public class JdkClientEngine implements ClientEngine {
private ClientConfig config;
/**
* 重定向次数计数器内部使用
*/
private int redirectCount;
/**
* 构造
@ -164,8 +160,8 @@ public class JdkClientEngine implements ClientEngine {
if (code != HttpURLConnection.HTTP_OK) {
if (HttpStatus.isRedirected(code)) {
message.url(getLocationUrl(message.handledUrl(), conn.header(HeaderName.LOCATION)));
if (redirectCount < message.maxRedirectCount()) {
redirectCount++;
if (conn.redirectCount < message.maxRedirectCount()) {
conn.redirectCount++;
return send(message, isAsync);
}
}

View File

@ -46,6 +46,10 @@ public class JdkHttpConnection implements HeaderOperation<JdkHttpConnection>, Cl
private final URL url;
private final Proxy proxy;
private final HttpURLConnection conn;
/**
* 重定向次数计数器内部使用
*/
protected int redirectCount;
/**
* 创建HttpConnection
@ -292,9 +296,9 @@ public class JdkHttpConnection implements HeaderOperation<JdkHttpConnection>, Cl
@Override
public String header(final String name) {
String headerField = this.conn.getHeaderField(name);
if(null == headerField){
if (null == headerField) {
final Map<String, ? extends Collection<String>> headers = headers();
headerField = CollUtil.getFirst(MapUtil.firstMatchValue(headers, entry-> StrUtil.equalsIgnoreCase(name, entry.getKey())));
headerField = CollUtil.getFirst(MapUtil.firstMatchValue(headers, entry -> StrUtil.equalsIgnoreCase(name, entry.getKey())));
}
return headerField;