use of io.vertx.ext.web.client.impl.HttpRequestImpl in project vertx-web by vert-x3.
the class PredicateInterceptor method handle.
@Override
public void handle(HttpContext<?> httpContext) {
if (httpContext.phase() == ClientPhase.RECEIVE_RESPONSE) {
// Run expectations
HttpRequestImpl request = (HttpRequestImpl) httpContext.request();
HttpClientResponse resp = httpContext.clientResponse();
List<ResponsePredicate> expectations = request.expectations;
if (expectations != null) {
for (ResponsePredicate expectation : expectations) {
ResponsePredicateResultImpl predicateResult;
try {
predicateResult = (ResponsePredicateResultImpl) expectation.apply(responseCopy(resp, httpContext, null));
} catch (Exception e) {
httpContext.fail(e);
return;
}
if (!predicateResult.succeeded()) {
ErrorConverter errorConverter = expectation.errorConverter();
if (!errorConverter.requiresBody()) {
predicateResult.setHttpResponse(responseCopy(resp, httpContext, null));
failOnPredicate(httpContext, errorConverter, predicateResult);
} else {
resp.bodyHandler(buffer -> {
predicateResult.setHttpResponse(responseCopy(resp, httpContext, buffer));
failOnPredicate(httpContext, errorConverter, predicateResult);
});
resp.resume();
}
return;
}
}
}
}
httpContext.next();
}
Aggregations