fix(测试跟踪): 禅道图片同步后不显示

--bug=1020301 --user=陈建星 【测试跟踪】github #20125, 同步禅道缺陷后,缺陷内容中的图片无法展示 https://www.tapd.cn/55049933/s/1312407
This commit is contained in:
chenjianxing 2022-12-06 11:25:24 +08:00 committed by jianxing
parent 951146df96
commit efbbf010ea
1 changed files with 19 additions and 20 deletions

View File

@ -21,6 +21,7 @@ public class SessionFilter implements WebFilter {
private static final String[] TO_SUB_SERVICE = new String[]{"/license", "/system", "/resource", "/sso/callback/logout", "/sso/callback/cas/logout"};
private static final String PERFORMANCE_DOWNLOAD_PREFIX = "/jmeter/";
private static final String API_DOWNLOAD_PREFIX = "/api/jmeter/";
private static final String TRACK_IMAGE_PREFIX = "/resource/md/get/url";
@Resource
private DiscoveryClient discoveryClient;
@ -36,15 +37,15 @@ public class SessionFilter implements WebFilter {
if (path.startsWith("/css") || path.startsWith("/js")) {
for (String prefix : PREFIX) {
if (path.contains(prefix)) {
ServerWebExchangeUtils.addOriginalRequestUrl(exchange, req.getURI());
String newPath = prefix + path;
ServerHttpRequest request = req.mutate().path(newPath).build();
exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR, request.getURI());
return chain.filter(exchange.mutate().request(request).build());
return addPrefix(prefix, exchange, chain);
}
}
}
if (path.startsWith(TRACK_IMAGE_PREFIX)) {
return addPrefix("/track", exchange, chain);
}
// 有些url直接转到 sub-service
for (String prefix : TO_SUB_SERVICE) {
if (path.startsWith(prefix)) {
@ -53,31 +54,29 @@ public class SessionFilter implements WebFilter {
break;
}
String service = svc.get();
ServerWebExchangeUtils.addOriginalRequestUrl(exchange, req.getURI());
String newPath = "/" + service + "/" + path;
ServerHttpRequest request = req.mutate().path(newPath).build();
exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR, request.getURI());
return chain.filter(exchange.mutate().request(request).build());
return addPrefix("/" + service + "/", exchange, chain);
}
}
// 从当前站点下载资源
if (path.startsWith(PERFORMANCE_DOWNLOAD_PREFIX)) {
ServerWebExchangeUtils.addOriginalRequestUrl(exchange, req.getURI());
String newPath = "/performance" + path;
ServerHttpRequest request = req.mutate().path(newPath).build();
exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR, request.getURI());
return chain.filter(exchange.mutate().request(request).build());
return addPrefix("/performance", exchange, chain);
}
if (path.startsWith(API_DOWNLOAD_PREFIX)) {
ServerWebExchangeUtils.addOriginalRequestUrl(exchange, req.getURI());
String newPath = "/api" + path;
ServerHttpRequest request = req.mutate().path(newPath).build();
exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR, request.getURI());
return chain.filter(exchange.mutate().request(request).build());
return addPrefix("/api", exchange, chain);
}
return chain.filter(exchange);
}
private Mono<Void> addPrefix(String prefix, final ServerWebExchange exchange, final WebFilterChain chain) {
ServerHttpRequest req = exchange.getRequest();
String path = req.getURI().getRawPath();
ServerWebExchangeUtils.addOriginalRequestUrl(exchange, req.getURI());
String newPath = prefix + path;
ServerHttpRequest request = req.mutate().path(newPath).build();
exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR, request.getURI());
return chain.filter(exchange.mutate().request(request).build());
}
}