Merge pull request #2828 from Charles7c/v5-dev

新增获取所有响应头的方法
This commit is contained in:
Golden Looly 2022-12-27 20:14:08 +08:00 committed by GitHub
commit 1a0c22b555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,7 @@ import java.io.Writer;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Collections; import java.util.Collections;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
@ -299,6 +300,22 @@ public class ServletUtil {
return headerMap; return headerMap;
} }
/**
* 获取响应所有的头header信息
*
* @param response 响应对象{@link HttpServletResponse}
* @return header值
*/
public static Map<String, Collection<String>> getHeaderMap(HttpServletResponse response) {
final Map<String, Collection<String>> headerMap = new HashMap<>();
final Collection<String> names = response.getHeaderNames();
for (String name : names) {
headerMap.put(name, response.getHeaders(name));
}
return headerMap;
}
/** /**
* 忽略大小写获得请求header中的信息 * 忽略大小写获得请求header中的信息