Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/main/java/io/apitally/common/RequestLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ public class RequestLogger {
"/_?heart[_-]?beats?$",
"/ping$",
"/ready$",
"/live$");
"/live$",
"/favicon(?:-[\\w-]+)?\\.(ico|png|svg)$",
"/apple-touch-icon(?:-[\\w-]+)?\\.png$",
"/robots\\.txt$",
"/sitemap\\.xml$",
"/manifest\\.json$",
"/site\\.webmanifest$",
"/service-worker\\.js$",
"/sw\\.js$",
"/\\.well-known/");
private static final List<String> EXCLUDE_USER_AGENT_PATTERNS = Arrays.asList(
"health[-_ ]?check",
"microsoft-azure-application-lb",
Expand Down Expand Up @@ -144,8 +153,16 @@ public void logRequest(Request request, Response response, Exception exception)
}

try {
String path = request.getPath();
if (path == null || path.isEmpty()) {
try {
path = new URL(request.getUrl()).getPath();
} catch (MalformedURLException e) {
path = "";
}
}
String userAgent = findHeader(request.getHeaders(), "user-agent");
if (shouldExcludePath(request.getPath()) || shouldExcludeUserAgent(userAgent)) {
if (shouldExcludePath(path) || shouldExcludeUserAgent(userAgent)) {
return;
}
if (config.getCallbacks() != null && config.getCallbacks().shouldExclude(request, response)) {
Expand Down Expand Up @@ -362,15 +379,15 @@ private void stopMaintenance() {
}

private boolean shouldExcludePath(String path) {
if (path == null) {
if (path == null || path.isEmpty()) {
return false;
}
return compiledPathExcludePatterns.stream()
.anyMatch(p -> p.matcher(path).find());
}

private boolean shouldExcludeUserAgent(String userAgent) {
return userAgent != null && compiledUserAgentExcludePatterns.stream()
return userAgent != null && !userAgent.isEmpty() && compiledUserAgentExcludePatterns.stream()
.anyMatch(p -> p.matcher(userAgent).find());
}

Expand Down