mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
f78e4fecb8
commit
b393d0d8f0
@ -71,7 +71,12 @@ public interface HeaderOperation<T extends HeaderOperation<T>> {
|
|||||||
* @return header值
|
* @return header值
|
||||||
*/
|
*/
|
||||||
default String header(final String name) {
|
default String header(final String name) {
|
||||||
final Collection<String> values = headers().get(name);
|
final Map<String, ? extends Collection<String>> headers = headers();
|
||||||
|
Collection<String> values = headers.get(name);
|
||||||
|
if(null == values){
|
||||||
|
// issue#I96U4T,根据RFC2616规范,header的name不区分大小写
|
||||||
|
values = MapUtil.firstMatchValue(headers, entry-> StrUtil.equalsIgnoreCase(name, entry.getKey()));
|
||||||
|
}
|
||||||
if (ArrayUtil.isNotEmpty(values)) {
|
if (ArrayUtil.isNotEmpty(values)) {
|
||||||
return CollUtil.getFirst(values);
|
return CollUtil.getFirst(values);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.http.client.engine.jdk;
|
package org.dromara.hutool.http.client.engine.jdk;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.lang.Opt;
|
import org.dromara.hutool.core.lang.Opt;
|
||||||
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.core.net.url.UrlUtil;
|
import org.dromara.hutool.core.net.url.UrlUtil;
|
||||||
import org.dromara.hutool.core.reflect.FieldUtil;
|
import org.dromara.hutool.core.reflect.FieldUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
@ -30,6 +32,7 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.ProtocolException;
|
import java.net.ProtocolException;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -288,7 +291,13 @@ public class JdkHttpConnection implements HeaderOperation<JdkHttpConnection>, Cl
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String header(final String name) {
|
public String header(final String name) {
|
||||||
return this.conn.getHeaderField(name);
|
String headerField = this.conn.getHeaderField(name);
|
||||||
|
if(null == headerField){
|
||||||
|
final Map<String, ? extends Collection<String>> headers = headers();
|
||||||
|
headerField = CollUtil.getFirst(MapUtil.firstMatchValue(headers, entry-> StrUtil.equalsIgnoreCase(name, entry.getKey())));
|
||||||
|
}
|
||||||
|
|
||||||
|
return headerField;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user