Skip to content

Commit 0817b8f

Browse files
committed
refactor(appsec): fetch both callbacks upfront before iterating file items
1 parent 37e7d09 commit 0817b8f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

dd-java-agent/instrumentation/commons-fileupload-1.5/src/main/java/datadog/trace/instrumentation/commons/fileupload/CommonsFileUploadAppSecModule.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ static void after(
6363
}
6464

6565
CallbackProvider cbp = AgentTracer.get().getCallbackProvider(RequestContextSlot.APPSEC);
66+
BiFunction<RequestContext, List<String>, Flow<Void>> filenamesCallback =
67+
cbp.getCallback(EVENTS.requestFilesFilenames());
68+
BiFunction<RequestContext, List<String>, Flow<Void>> contentCallback =
69+
cbp.getCallback(EVENTS.requestFilesContent());
70+
if (filenamesCallback == null && contentCallback == null) {
71+
return;
72+
}
6673

6774
List<String> filenames = new ArrayList<>();
6875
for (FileItem fileItem : fileItems) {
@@ -79,8 +86,6 @@ static void after(
7986
}
8087

8188
// Fire filenames event
82-
BiFunction<RequestContext, List<String>, Flow<Void>> filenamesCallback =
83-
cbp.getCallback(EVENTS.requestFilesFilenames());
8489
if (filenamesCallback != null) {
8590
Flow<Void> flow = filenamesCallback.apply(reqCtx, filenames);
8691
Flow.Action action = flow.getAction();
@@ -97,8 +102,6 @@ static void after(
97102
}
98103

99104
// Fire content event only if not blocked
100-
BiFunction<RequestContext, List<String>, Flow<Void>> contentCallback =
101-
cbp.getCallback(EVENTS.requestFilesContent());
102105
if (contentCallback == null) {
103106
return;
104107
}

0 commit comments

Comments
 (0)