|
|
|
@ -109,19 +109,37 @@ public class RouterHandler extends Handler {
|
|
|
|
|
return formBodyBuilder.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 方法2:使用Set集合(推荐,性能更好)
|
|
|
|
|
private static final Set<String> STATIC_EXTENSIONS = new HashSet<>(Arrays.asList(
|
|
|
|
|
"html", "js", "css", "png", "jpg", "jpeg", "gif", "ico", "svg",
|
|
|
|
|
"woff", "woff2", "ttf", "eot", "map", "json", "xml", "txt"
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为静态资源的方法
|
|
|
|
|
private boolean isStaticResource(String servletPath) {
|
|
|
|
|
int lastDotIndex = servletPath.lastIndexOf('.');
|
|
|
|
|
if (lastDotIndex == -1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
String extension = servletPath.substring(lastDotIndex + 1).toLowerCase();
|
|
|
|
|
return STATIC_EXTENSIONS.contains(extension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void handle(String target, HttpServletRequest req, HttpServletResponse res, boolean[] isHandled) {
|
|
|
|
|
//可以正确获取到URL的完整路径
|
|
|
|
|
String servletPath = req.getServletPath();
|
|
|
|
|
String queryString = req.getQueryString();
|
|
|
|
|
//对于根目录的访问,放行
|
|
|
|
|
if (servletPath.equals("/")) {
|
|
|
|
|
if (servletPath.equals("/") || isStaticResource(servletPath)) {
|
|
|
|
|
next.handle(target, req, res, isHandled);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果是白名单,不检查jwt,否则需要检查jwt
|
|
|
|
|
if (!GwApplication.whiteSet.contains(servletPath)) {
|
|
|
|
|
|
|
|
|
|
//微服务间的调用视为内部调用
|
|
|
|
|
if (req.getServletPath().endsWith("_Internal")) {
|
|
|
|
|
renderJson(res, new RetBean(RetBean.ERROR, "微服务间内部接口调用,是不需要走网关的!").toString());
|
|
|
|
|