@Override public void handle(Context context) throws Exception { HttpMethod method = context.getRequest().getMethod(); if (method.isOptions() && !handlers.containsKey(HttpMethod.OPTIONS)) { List<String> parts = new ArrayList<>(Collections2.transform(handlers.keySet(), HttpMethod::getName)); Collections.sort(parts); String methods = JOINER.join(parts); context.getResponse().getHeaders().add(HttpHeaderConstants.ALLOW, methods); context.getResponse().status(200).send(); } else { Handler handler = handlers.get(method); if (handler != null) { context.insert(handler); return; } if (method.isHead()) { Handler getHandler = handlers.get(HttpMethod.GET); if (getHandler != null) { context.insert(getHandler); return; } } NO_METHOD_HANDLER.handle(context); } }
public void handle(Context context) { ratpack.http.HttpMethod requestMethod = context.getRequest().getMethod(); if (requestMethod == method || requestMethod.name(method.getName())) { context.next(); } else if (requestMethod.isOptions()) { Response response = context.getResponse(); response.getHeaders().add(HttpHeaderConstants.ALLOW, method); response.status(200).send(); } else { context.clientError(405); } } }