mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix redirect
This commit is contained in:
parent
b393d0d8f0
commit
868a0e6c3c
@ -42,10 +42,6 @@ import java.util.List;
|
|||||||
public class JdkClientEngine implements ClientEngine {
|
public class JdkClientEngine implements ClientEngine {
|
||||||
|
|
||||||
private ClientConfig config;
|
private ClientConfig config;
|
||||||
/**
|
|
||||||
* 重定向次数计数器,内部使用
|
|
||||||
*/
|
|
||||||
private int redirectCount;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
@ -164,8 +160,8 @@ public class JdkClientEngine implements ClientEngine {
|
|||||||
if (code != HttpURLConnection.HTTP_OK) {
|
if (code != HttpURLConnection.HTTP_OK) {
|
||||||
if (HttpStatus.isRedirected(code)) {
|
if (HttpStatus.isRedirected(code)) {
|
||||||
message.url(getLocationUrl(message.handledUrl(), conn.header(HeaderName.LOCATION)));
|
message.url(getLocationUrl(message.handledUrl(), conn.header(HeaderName.LOCATION)));
|
||||||
if (redirectCount < message.maxRedirectCount()) {
|
if (conn.redirectCount < message.maxRedirectCount()) {
|
||||||
redirectCount++;
|
conn.redirectCount++;
|
||||||
return send(message, isAsync);
|
return send(message, isAsync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,10 @@ public class JdkHttpConnection implements HeaderOperation<JdkHttpConnection>, Cl
|
|||||||
private final URL url;
|
private final URL url;
|
||||||
private final Proxy proxy;
|
private final Proxy proxy;
|
||||||
private final HttpURLConnection conn;
|
private final HttpURLConnection conn;
|
||||||
|
/**
|
||||||
|
* 重定向次数计数器,内部使用
|
||||||
|
*/
|
||||||
|
protected int redirectCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建HttpConnection
|
* 创建HttpConnection
|
||||||
@ -292,9 +296,9 @@ public class JdkHttpConnection implements HeaderOperation<JdkHttpConnection>, Cl
|
|||||||
@Override
|
@Override
|
||||||
public String header(final String name) {
|
public String header(final String name) {
|
||||||
String headerField = this.conn.getHeaderField(name);
|
String headerField = this.conn.getHeaderField(name);
|
||||||
if(null == headerField){
|
if (null == headerField) {
|
||||||
final Map<String, ? extends Collection<String>> headers = headers();
|
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;
|
return headerField;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user