feat:过滤搜索引擎的请求
This commit is contained in:
parent
526a070c33
commit
c70bc96584
@ -22,6 +22,7 @@ import com.fanxb.backend.util.NetUtil;
|
|||||||
import com.fanxb.backend.util.ThreadPoolUtil;
|
import com.fanxb.backend.util.ThreadPoolUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -31,7 +32,9 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用管理
|
* 应用管理
|
||||||
@ -72,8 +75,16 @@ public class ApplicationServiceImpl implements ApplicationService {
|
|||||||
return new ApplicationSignVo(po.getKey(), po.getSecret());
|
return new ApplicationSignVo(po.getKey(), po.getSecret());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Pattern PATTERN = Pattern.compile("googlebot|bingbot|yandex|baiduspider|360Spider|Sogou Spider|Bytespider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\\/0\\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key, String path, boolean notAdd) throws IOException {
|
public void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key, String path, boolean notAdd) throws IOException {
|
||||||
|
//检查是否搜索引擎的请求
|
||||||
|
String agent = request.getHeader(HttpHeaders.USER_AGENT);
|
||||||
|
if (agent != null && PATTERN.matcher(agent.toLowerCase(Locale.ROOT)).find()) {
|
||||||
|
//搜索引擎的直接返回
|
||||||
|
return;
|
||||||
|
}
|
||||||
int hostId = getHostId(key);
|
int hostId = getHostId(key);
|
||||||
HostPo hostData = hostDao.getUvPvById(hostId);
|
HostPo hostData = hostDao.getUvPvById(hostId);
|
||||||
DetailPagePo detailData = detailPageDao.getUvPvById(hostId, path);
|
DetailPagePo detailData = detailPageDao.getUvPvById(hostId, path);
|
||||||
@ -190,5 +201,4 @@ public class ApplicationServiceImpl implements ApplicationService {
|
|||||||
return hostId;
|
return hostId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user