mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1374,4 +1374,43 @@ public class MapUtil extends MapGetUtil {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历Map,返回第一个匹配的value值
|
||||
*
|
||||
* @param map map
|
||||
* @param predicate 匹配条件
|
||||
* @param <K> 键类型
|
||||
* @param <V> 值类型
|
||||
* @return value值
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static <K, V> V firstMatchValue(final Map<K, V> map, final Predicate<Entry<K, V>> predicate) {
|
||||
final Entry<K, V> kvEntry = firstMatch(map, predicate);
|
||||
if (null != kvEntry) {
|
||||
return kvEntry.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历Map,返回第一个匹配的entry值
|
||||
*
|
||||
* @param map map
|
||||
* @param predicate 匹配条件
|
||||
* @param <K> 键类型
|
||||
* @param <V> 值类型
|
||||
* @return entry
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static <K, V> Entry<K, V> firstMatch(final Map<K, V> map, final Predicate<Entry<K, V>> predicate) {
|
||||
if (isNotEmpty(map)) {
|
||||
for (final Entry<K, V> entry : map.entrySet()) {
|
||||
if (predicate.test(entry)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@ package org.dromara.hutool.http.client.engine.jdk;
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.io.IoUtil;
|
||||
import org.dromara.hutool.core.io.stream.EmptyInputStream;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
import org.dromara.hutool.http.HttpException;
|
||||
import org.dromara.hutool.http.HttpUtil;
|
||||
@@ -94,7 +96,11 @@ public class JdkHttpResponse implements Response, Closeable {
|
||||
|
||||
@Override
|
||||
public String header(final String name) {
|
||||
final List<String> headerValues = this.headers.get(name);
|
||||
List<String> headerValues = this.headers.get(name);
|
||||
if(null == headerValues){
|
||||
// issue#I96U4T,根据RFC2616规范,header的name不区分大小写
|
||||
headerValues = MapUtil.firstMatchValue(this.headers, entry-> StrUtil.equalsIgnoreCase(name, entry.getKey()));
|
||||
}
|
||||
if (ArrayUtil.isNotEmpty(headerValues)) {
|
||||
return headerValues.get(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user