|
27 | 27 | import net.bytebuddy.asm.Advice; |
28 | 28 | import org.glassfish.jersey.media.multipart.BodyPart; |
29 | 29 | import org.glassfish.jersey.media.multipart.FormDataBodyPart; |
| 30 | +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; |
30 | 31 | import org.glassfish.jersey.media.multipart.MultiPart; |
31 | 32 | import org.glassfish.jersey.message.internal.MediaTypes; |
32 | 33 |
|
@@ -110,6 +111,41 @@ static void after( |
110 | 111 | reqCtx.getTraceSegment().effectivelyBlocked(); |
111 | 112 | } |
112 | 113 | } |
| 114 | + |
| 115 | + BiFunction<RequestContext, List<String>, Flow<Void>> filenamesCallback = |
| 116 | + cbp.getCallback(EVENTS.requestFilesFilenames()); |
| 117 | + if (filenamesCallback == null) { |
| 118 | + return; |
| 119 | + } |
| 120 | + List<String> filenames = new ArrayList<>(); |
| 121 | + for (BodyPart bodyPart : ret.getBodyParts()) { |
| 122 | + if (!(bodyPart instanceof FormDataBodyPart)) { |
| 123 | + continue; |
| 124 | + } |
| 125 | + FormDataBodyPart dataBodyPart = (FormDataBodyPart) bodyPart; |
| 126 | + FormDataContentDisposition cd = dataBodyPart.getFormDataContentDisposition(); |
| 127 | + if (cd == null) { |
| 128 | + continue; |
| 129 | + } |
| 130 | + String filename = cd.getFileName(); |
| 131 | + if (filename != null && !filename.isEmpty()) { |
| 132 | + filenames.add(filename); |
| 133 | + } |
| 134 | + } |
| 135 | + if (filenames.isEmpty()) { |
| 136 | + return; |
| 137 | + } |
| 138 | + Flow<Void> filenamesFlow = filenamesCallback.apply(reqCtx, filenames); |
| 139 | + Flow.Action filenamesAction = filenamesFlow.getAction(); |
| 140 | + if (t == null && filenamesAction instanceof Flow.Action.RequestBlockingAction) { |
| 141 | + Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) filenamesAction; |
| 142 | + BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction(); |
| 143 | + if (blockResponseFunction != null) { |
| 144 | + blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba); |
| 145 | + t = new BlockingException("Blocked request (multipart file upload)"); |
| 146 | + reqCtx.getTraceSegment().effectivelyBlocked(); |
| 147 | + } |
| 148 | + } |
113 | 149 | } |
114 | 150 | } |
115 | 151 | } |
0 commit comments