fix(log/interceptor): 修复全局配置和局部配置包含请求、响应体冲突

This commit is contained in:
2024-09-24 22:14:50 +08:00
parent 3535ac64f7
commit be4dec5a30

View File

@@ -28,14 +28,12 @@ import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.ContentCachingRequestWrapper; import org.springframework.web.util.ContentCachingRequestWrapper;
import org.springframework.web.util.ContentCachingResponseWrapper; import org.springframework.web.util.ContentCachingResponseWrapper;
import org.springframework.web.util.WebUtils; import org.springframework.web.util.WebUtils;
import top.continew.starter.log.core.enums.Include;
import top.continew.starter.log.interceptor.autoconfigure.LogProperties; import top.continew.starter.log.interceptor.autoconfigure.LogProperties;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
/** /**
* 日志过滤器 * 日志过滤器
@@ -123,9 +121,7 @@ public class LogFilter extends OncePerRequestFilter implements Ordered {
* @return truefalse * @return truefalse
*/ */
private boolean isRequestWrapper(HttpServletRequest request) { private boolean isRequestWrapper(HttpServletRequest request) {
Set<Include> includeSet = logProperties.getIncludes(); return !(request instanceof ContentCachingRequestWrapper);
return !(request instanceof ContentCachingRequestWrapper) && (includeSet
.contains(Include.REQUEST_BODY) || includeSet.contains(Include.REQUEST_PARAM));
} }
/** /**
@@ -135,9 +131,7 @@ public class LogFilter extends OncePerRequestFilter implements Ordered {
* @return truefalse * @return truefalse
*/ */
private boolean isResponseWrapper(HttpServletResponse response) { private boolean isResponseWrapper(HttpServletResponse response) {
Set<Include> includeSet = logProperties.getIncludes(); return !(response instanceof ContentCachingResponseWrapper);
return !(response instanceof ContentCachingResponseWrapper) && (includeSet
.contains(Include.RESPONSE_BODY) || includeSet.contains(Include.RESPONSE_PARAM));
} }
/** /**