use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class ZuulFilterChainRunner method filter.
@Override
public void filter(T inMesg, HttpContent chunk) {
String filterName = "-";
try (TaskCloseable ignored = PerfMark.traceTask(this, s -> s.getClass().getSimpleName() + ".filterChunk")) {
addPerfMarkTags(inMesg);
Preconditions.checkNotNull(inMesg, "input message");
final AtomicInteger runningFilterIdx = getRunningFilterIndex(inMesg);
final int limit = runningFilterIdx.get();
for (int i = 0; i < limit; i++) {
final ZuulFilter<T, T> filter = filters[i];
filterName = filter.filterName();
if ((!filter.isDisabled()) && (!shouldSkipFilter(inMesg, filter))) {
final HttpContent newChunk = filter.processContentChunk(inMesg, chunk);
if (newChunk == null) {
// Filter wants to break the chain and stop propagating this chunk any further
return;
}
// deallocate original chunk if necessary
if ((newChunk != chunk) && (chunk.refCnt() > 0)) {
chunk.release(chunk.refCnt());
}
chunk = newChunk;
}
}
if (limit >= filters.length) {
// Filter chain has run to end, pass down the channel pipeline
invokeNextStage(inMesg, chunk);
} else {
inMesg.bufferBodyContents(chunk);
boolean isAwaitingBody = isFilterAwaitingBody(inMesg);
// Record passport states for start and end of buffering bodies.
if (isAwaitingBody) {
CurrentPassport passport = CurrentPassport.fromSessionContext(inMesg.getContext());
if (inMesg.hasCompleteBody()) {
if (inMesg instanceof HttpRequestMessage) {
passport.addIfNotAlready(PassportState.FILTERS_INBOUND_BUF_END);
} else if (inMesg instanceof HttpResponseMessage) {
passport.addIfNotAlready(PassportState.FILTERS_OUTBOUND_BUF_END);
}
} else {
if (inMesg instanceof HttpRequestMessage) {
passport.addIfNotAlready(PassportState.FILTERS_INBOUND_BUF_START);
} else if (inMesg instanceof HttpResponseMessage) {
passport.addIfNotAlready(PassportState.FILTERS_OUTBOUND_BUF_START);
}
}
}
if (isAwaitingBody && inMesg.hasCompleteBody()) {
// whole body has arrived, resume filter chain
runFilters(inMesg, runningFilterIdx);
}
}
} catch (Exception ex) {
handleException(inMesg, filterName, ex);
}
}
Aggregations