修复resp重复写BUG
This commit is contained in:
@@ -97,29 +97,24 @@ public class HttpLogFilter extends BaseFilter implements Ordered, BaseParams {
|
|||||||
// 记录请求日志
|
// 记录请求日志
|
||||||
LogBus.init(LogLevel.INFO, LogBusBaseType.HTTP_REQUEST).data(log).save();
|
LogBus.init(LogLevel.INFO, LogBusBaseType.HTTP_REQUEST).data(log).save();
|
||||||
|
|
||||||
// 包装请求
|
// 包装请求和响应
|
||||||
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request, DEFAULT_CACHE_LIMIT);
|
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request, DEFAULT_CACHE_LIMIT);
|
||||||
|
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
|
||||||
|
|
||||||
// 响应数据
|
// 处理请求
|
||||||
Object respData;
|
filterChain.doFilter(requestWrapper, responseWrapper);
|
||||||
if (PathPatternUtils.match(RESP_WHITE_LIST, uri)) {
|
|
||||||
// 处理请求
|
|
||||||
filterChain.doFilter(requestWrapper, response);
|
|
||||||
respData = "ignore";
|
|
||||||
} else {
|
|
||||||
// 包装响应
|
|
||||||
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
|
|
||||||
// 处理请求
|
|
||||||
filterChain.doFilter(requestWrapper, responseWrapper);
|
|
||||||
// 获取响应内容
|
|
||||||
respData = getContent(responseWrapper.getContentAsByteArray());
|
|
||||||
// 将内容复制回原始响应
|
|
||||||
responseWrapper.copyBodyToResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取请求参数
|
// 获取请求参数
|
||||||
Object reqParam = getContent(requestWrapper.getContentAsByteArray());
|
Object reqParam = getContent(requestWrapper.getContentAsByteArray());
|
||||||
|
Object respData;
|
||||||
|
if (!PathPatternUtils.match(RESP_WHITE_LIST, uri)) {
|
||||||
|
// 获取响应内容
|
||||||
|
respData = getContent(responseWrapper.getContentAsByteArray());
|
||||||
|
} else {
|
||||||
|
respData = "ignore";
|
||||||
|
}
|
||||||
|
// 将内容复制回原始响应
|
||||||
|
responseWrapper.copyBodyToResponse();
|
||||||
// 保存日志
|
// 保存日志
|
||||||
log.put("reqBody", reqParam);
|
log.put("reqBody", reqParam);
|
||||||
log.put("respData", respData);
|
log.put("respData", respData);
|
||||||
|
|||||||
Reference in New Issue
Block a user