记得上下班打卡 | git大法好,push需谨慎

Commit 1fb32bc3 authored by wangyifan's avatar wangyifan

响应头添加自定义参数

parent 4fbc295e
......@@ -12,11 +12,21 @@ import javax.servlet.http.HttpServletResponse;
@Component
public class GlobalLogTrackInterceptor extends HandlerInterceptorAdapter {
private static final String LNS_TRANCE_ID = "lnsTranceId";
private static final String X_SERVER_HEADER = "X-Server";
private static final String POD_NAME_ENV = "POD_NAME";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String t = MDC.get(LNS_TRANCE_ID);
MDC.put(LNS_TRANCE_ID, null == t ? String.valueOf(System.nanoTime()) : t);
// 从环境变量获取POD_NAME并添加到响应头
String podName = System.getenv(POD_NAME_ENV);
if (podName != null && !podName.isEmpty()) {
log.info("[preHandle] podName: {}", podName);
response.setHeader(X_SERVER_HEADER, podName);
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment