mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-31 22:57:19 +08:00 
			
		
		
		
	refactor(log/httptrace-pro): 重构请求头及响应头信息获取
This commit is contained in:
		| @@ -16,6 +16,7 @@ | ||||
|  | ||||
| package top.charles7c.continew.starter.core.util; | ||||
|  | ||||
| import cn.hutool.core.map.MapUtil; | ||||
| import cn.hutool.http.useragent.UserAgent; | ||||
| import cn.hutool.http.useragent.UserAgentUtil; | ||||
| import jakarta.servlet.http.HttpServletRequest; | ||||
| @@ -26,7 +27,7 @@ import org.springframework.web.context.request.RequestContextHolder; | ||||
| import org.springframework.web.context.request.ServletRequestAttributes; | ||||
| import top.charles7c.continew.starter.core.constant.StringConstants; | ||||
|  | ||||
| import java.util.Objects; | ||||
| import java.util.*; | ||||
|  | ||||
| /** | ||||
|  * Servlet 工具类 | ||||
| @@ -103,6 +104,21 @@ public class ServletUtils { | ||||
|         return userAgent.getOs().getName(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取响应所有的头(header)信息 | ||||
|      * | ||||
|      * @param response 响应对象{@link HttpServletResponse} | ||||
|      * @return header值 | ||||
|      */ | ||||
|     public static Map<String, String> getHeaderMap(HttpServletResponse response) { | ||||
|         final Collection<String> headerNames = response.getHeaderNames(); | ||||
|         final Map<String, String> headerMap = MapUtil.newHashMap(headerNames.size(), true); | ||||
|         for (String name : headerNames) { | ||||
|             headerMap.put(name, response.getHeader(name)); | ||||
|         } | ||||
|         return headerMap; | ||||
|     } | ||||
|  | ||||
|     private static ServletRequestAttributes getServletRequestAttributes() { | ||||
|         return (ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes()); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user