use of com.spotify.apollo.StatusType in project apollo by spotify.
the class RequestRunnableImpl method matchAndRun.
private void matchAndRun(BiConsumer<OngoingRequest, RuleMatch<Endpoint>> matchContinuation) {
final Request request = ongoingRequest.request();
final Optional<RuleMatch<Endpoint>> match;
try {
match = applicationRouter.match(request);
} catch (InvalidUriException e) {
LOG.debug("bad uri {} {} {}", request.method(), request.uri(), BAD_REQUEST, e);
ongoingRequest.reply(forStatus(BAD_REQUEST));
return;
}
if (!match.isPresent()) {
Collection<String> methods = applicationRouter.getMethodsForValidRules(request);
if (methods.isEmpty()) {
LOG.debug("not found {} {} {}", request.method(), request.uri(), NOT_FOUND);
ongoingRequest.reply(forStatus(NOT_FOUND));
} else {
StatusType statusCode;
if ("OPTIONS".equals(request.method())) {
statusCode = NO_CONTENT;
} else {
statusCode = METHOD_NOT_ALLOWED;
LOG.debug("wrong method {} {} {}", request.method(), request.uri(), statusCode);
}
methods = Sets.newTreeSet(methods);
methods.add("OPTIONS");
ongoingRequest.reply(Response.<ByteString>forStatus(statusCode).withHeader("Allow", Joiner.on(", ").join(methods)));
}
return;
}
matchContinuation.accept(ongoingRequest, match.get());
}
Aggregations