mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
添加响应时间响应头
This commit is contained in:
@@ -22,12 +22,28 @@ import cn.lihongjie.coal.supplier.entity.SupplierEntity;
|
||||
import cn.lihongjie.coal.syslog.entity.SysLogEntity;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.basic.Inet;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface CommonMapper {
|
||||
|
||||
default Inet stringToInet(String s){
|
||||
return new Inet(s);
|
||||
}
|
||||
|
||||
default Inet inetToInet(Inet s){
|
||||
return new Inet(s.getAddress());
|
||||
}
|
||||
|
||||
|
||||
default String inetToString(Inet s){
|
||||
return s.getAddress();
|
||||
}
|
||||
|
||||
|
||||
default Integer toInt(String s) {
|
||||
try {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ public class Constants {
|
||||
public static final String RATE_LIMIT_GLOBAL_USER_PREFIX = "global-user-rl-";
|
||||
public static final String CACHE_ADDRESS_TYPE = "addressType";
|
||||
public static final String CACHE_CLIENT_RANDOM_PREFIX = "clientRandom::";
|
||||
public static final String HTTP_HEADER_RESPONSE_TIME = "X-Response-Time";
|
||||
public static String SYSCONFIG_ENABLE_CAPTCHA = "enable_captcha";
|
||||
public static String SYSCONFIG_ENABLE_REQUEST_SIGN = "enable_request_sign";
|
||||
public static String SYSCONFIG_SESSION_TIMEOUT = "session_timeout";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.lihongjie.coal.filter;
|
||||
|
||||
import cn.lihongjie.coal.common.Constants;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -22,13 +24,16 @@ import java.io.IOException;
|
||||
@Order(0)
|
||||
@Slf4j
|
||||
public class CacheFilter extends OncePerRequestFilter {
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
var req = new ContentCachingRequestWrapper(request);
|
||||
var res = new ContentCachingResponseWrapper(response);
|
||||
filterChain.doFilter(req, res);
|
||||
long end = System.currentTimeMillis();
|
||||
res.addHeader(Constants.HTTP_HEADER_RESPONSE_TIME, String.valueOf(end - start));
|
||||
res.copyBodyToResponse();
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CacheConfig {
|
||||
ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
||||
return RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofMinutes(10))
|
||||
.disableCachingNullValues()
|
||||
|
||||
.serializeValuesWith(
|
||||
RedisSerializationContext.SerializationPair.fromSerializer(
|
||||
new GenericJackson2JsonRedisSerializer(objectMapper)));
|
||||
|
||||
Reference in New Issue
Block a user