Skip to content

feat: optimize operation filter #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public static <TRequest, TResponse> Pair<TRequest, TResponse> onServiceEnter(
return null;
}

// skip operation for excludeServiceOperations、includeServiceOperations
if (shouldSkipOperation(adapter, httpServletRequest)) {
CaseEventDispatcher.onEvent(CaseEvent.ofEnterEvent());
return null;
}
// 302 Redirect request
String redirectRecordId = getRedirectRecordId(adapter, httpServletRequest);
if (StringUtil.isNotEmpty(redirectRecordId)) {
Expand Down Expand Up @@ -237,17 +242,6 @@ private static <TRequest> boolean shouldSkip(ServletAdapter<TRequest, ?> adapter
return false;
}
String pattern = adapter.getPattern(httpServletRequest);
// As long as one parameter is hit in includeServiceOperations, the operation will not be skipped
if (CollectionUtil.isNotEmpty(Config.get().getIncludeServiceOperations()) &&
!(IgnoreUtils.includeOperation(pattern) ||
IgnoreUtils.includeOperation(requestURI))) {
return true;
}
// As long as one parameter is hit in excludeServiceOperations, the operation will be skipped
if (IgnoreUtils.excludeOperation(pattern) ||
IgnoreUtils.excludeOperation(requestURI)) {
return true;
}

// Filter invalid servlet path suffix
if (FILTERED_GET_URL_SUFFIX.stream().anyMatch(requestURI::endsWith)) {
Expand All @@ -263,6 +257,38 @@ private static <TRequest> boolean shouldSkip(ServletAdapter<TRequest, ?> adapter
return Config.get().invalidRecord(pattern);
}

private static <TRequest> boolean shouldSkipOperation(ServletAdapter<TRequest, ?> adapter,
TRequest httpServletRequest) {
String caseId = adapter.getRequestHeader(httpServletRequest, ArexConstants.RECORD_ID);
// Replay scene
if (StringUtil.isNotEmpty(caseId)) {
return Config.get().getBoolean(ConfigConstants.DISABLE_REPLAY, false);
}

String forceRecord = adapter.getRequestHeader(httpServletRequest,
ArexConstants.FORCE_RECORD, ArexConstants.HEADER_X_PREFIX);
// Do not skip if header with arex-force-record=true
if (Boolean.parseBoolean(forceRecord)) {
return false;
}

String requestURI = adapter.getRequestURI(httpServletRequest);
if (StringUtil.isEmpty(requestURI)) {
return false;
}

String pattern = adapter.getPattern(httpServletRequest);
// As long as one parameter is hit in includeServiceOperations, the operation will not be skipped
if (CollectionUtil.isNotEmpty(Config.get().getIncludeServiceOperations()) &&
!(IgnoreUtils.includeOperation(pattern) ||
IgnoreUtils.includeOperation(requestURI))) {
return true;
}
// As long as one parameter is hit in excludeServiceOperations, the operation will be skipped
return IgnoreUtils.excludeOperation(pattern) ||
IgnoreUtils.excludeOperation(requestURI);
}

private static <TRequest, TResponse> String getRedirectRecordId(ServletAdapter<TRequest, TResponse> adapter,
TRequest httpServletRequest) {
String redirectRecordId = adapter.getParameterFromQueryString(httpServletRequest, ArexConstants.RECORD_ID);
Expand Down
Loading