mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 优化魔法值
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package com.ruoyi.common.filter;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.io.IoUtil;
 | 
			
		||||
import com.ruoyi.common.constant.Constants;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.ReadListener;
 | 
			
		||||
import javax.servlet.ServletInputStream;
 | 
			
		||||
@@ -23,8 +24,8 @@ public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper {
 | 
			
		||||
 | 
			
		||||
    public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException {
 | 
			
		||||
        super(request);
 | 
			
		||||
        request.setCharacterEncoding("UTF-8");
 | 
			
		||||
        response.setCharacterEncoding("UTF-8");
 | 
			
		||||
        request.setCharacterEncoding(Constants.UTF8);
 | 
			
		||||
        response.setCharacterEncoding(Constants.UTF8);
 | 
			
		||||
 | 
			
		||||
        body = IoUtil.readUtf8(request.getInputStream()).getBytes(StandardCharsets.UTF_8);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
package com.ruoyi.common.filter;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.extra.servlet.ServletUtil;
 | 
			
		||||
import com.ruoyi.common.utils.StringUtils;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.*;
 | 
			
		||||
@@ -48,7 +49,7 @@ public class XssFilter implements Filter {
 | 
			
		||||
        String url = request.getServletPath();
 | 
			
		||||
        String method = request.getMethod();
 | 
			
		||||
        // GET DELETE 不过滤
 | 
			
		||||
        if (method == null || method.matches("GET") || method.matches("DELETE")) {
 | 
			
		||||
        if (method == null || method.matches(ServletUtil.METHOD_GET) || method.matches(ServletUtil.METHOD_DELETE)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        return StringUtils.matches(url, excludes);
 | 
			
		||||
 
 | 
			
		||||
@@ -89,10 +89,9 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
 | 
			
		||||
    /**
 | 
			
		||||
     * 是否是Json请求
 | 
			
		||||
     *
 | 
			
		||||
     * @param request
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isJsonRequest() {
 | 
			
		||||
        String header = super.getHeader(HttpHeaders.CONTENT_TYPE);
 | 
			
		||||
        return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -117,7 +117,7 @@ public class ServletUtils extends ServletUtil {
 | 
			
		||||
    public static boolean isAjaxRequest(HttpServletRequest request) {
 | 
			
		||||
 | 
			
		||||
        String accept = request.getHeader("accept");
 | 
			
		||||
        if (accept != null && accept.contains("application/json")) {
 | 
			
		||||
        if (accept != null && accept.contains(MediaType.APPLICATION_JSON_VALUE)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -21,10 +21,10 @@ import java.io.IOException;
 | 
			
		||||
public class JacksonUtil {
 | 
			
		||||
    private static Logger logger = LoggerFactory.getLogger(JacksonUtil.class);
 | 
			
		||||
 | 
			
		||||
    private final static ObjectMapper objectMapper = new ObjectMapper();
 | 
			
		||||
    private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 | 
			
		||||
 | 
			
		||||
    public static ObjectMapper getInstance() {
 | 
			
		||||
        return objectMapper;
 | 
			
		||||
        return OBJECT_MAPPER;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -28,11 +28,13 @@ import java.util.Map;
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
 | 
			
		||||
 | 
			
		||||
    public static final String PROD_PROFILE = "prod";
 | 
			
		||||
 | 
			
		||||
    private final TransmittableThreadLocal<StopWatch> invokeTimeTL = new TransmittableThreadLocal<>();
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
 | 
			
		||||
        if (!"prod".equals(SpringUtils.getActiveProfile())) {
 | 
			
		||||
        if (!PROD_PROFILE.equals(SpringUtils.getActiveProfile())) {
 | 
			
		||||
            String url = request.getMethod() + " " + request.getRequestURI();
 | 
			
		||||
 | 
			
		||||
            // 打印请求参数
 | 
			
		||||
@@ -67,7 +69,7 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
 | 
			
		||||
        if (!"prod".equals(SpringUtils.getActiveProfile())) {
 | 
			
		||||
        if (!PROD_PROFILE.equals(SpringUtils.getActiveProfile())) {
 | 
			
		||||
            StopWatch stopWatch = invokeTimeTL.get();
 | 
			
		||||
            stopWatch.stop();
 | 
			
		||||
            log.debug("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user