@Override public String getRequestMethod() { return req.method(); }
@Override public String getRequestMethod() { return req.method(); }
@Override public String method() { return req.method(); }
/** * Creates a new {@link CsrfHandler} handler and use the given name to save the token in the * {@link Session} and or extract the token from incoming requests. * * @param name Token's name. */ public CsrfHandler(final String name) { this.name = requireNonNull(name, "Name is required."); tokenGen(req -> UUID.randomUUID().toString()); requireTokenOn(req -> REQUIRE_ON.contains(req.method())); }
@Override public void handle(final Request req, final Response rsp) throws Exception { if (!rsp.header(ALLOW).isSet()) { Set<String> allow = new LinkedHashSet<>(); Set<String> methods = new LinkedHashSet<>(Route.METHODS); String path = req.path(); methods.remove(req.method()); for (String method : methods) { routes.stream() .filter(route -> route.matches(method, path, MediaType.all, MediaType.ALL).isPresent()) .forEach(route -> allow.add(route.method())); } rsp.header(ALLOW, Joiner.on(SEP).join(allow)) .length(0) .status(Status.OK); } }
sb.append(BL).append(df.apply(timestamp)).append(BR); sb.append(SP); sb.append(Q).append(req.method()); sb.append(SP); sb.append(req.path());
req.method(), req.path(), req.route().print(6), err); rsp.type(MediaType.html).send(writer.toString());
@Override public void handle(final Request req, final Response rsp, final Err ex) throws Throwable { log.error("execution of: {}{} resulted in exception\nRoute:\n{}\n\nStacktrace:", req.method(), req.path(), req.route().print(6), ex); Config conf = req.require(Config.class); boolean stackstrace = Try.apply(() -> conf.getBoolean("err.stacktrace")) .orElse(req.require(Env.class).name().equals("dev")); rsp.send( Results .when(MediaType.html, () -> Results.html(VIEW).put("err", ex.toMap(stackstrace))) .when(MediaType.all, () -> ex.toMap(stackstrace))); }
private void preflight(final Cors cors, final Request req, final Response rsp, final String origin) { /** * Allowed method */ boolean allowMethod = req.header(AC_REQUEST_METHOD).toOptional() .map(cors::allowMethod) .orElse(false); if (!allowMethod) { return; } /** * Allowed headers */ List<String> headers = req.header(AC_REQUEST_HEADERS).toOptional().map(header -> Splitter.on(',').trimResults().omitEmptyStrings().splitToList(header) ).orElse(Collections.emptyList()); if (!cors.allowHeaders(headers)) { return; } /** * Allowed methods */ rsp.header(AC_ALLOW_METHODS, join(cors.allowedMethods())); List<String> allowedHeaders = cors.anyHeader() ? headers : cors.allowedHeaders(); rsp.header(AC_ALLOW_HEADERS, join(allowedHeaders));
@Override public String method() { return req.method(); }
@Override public String getRequestMethod() { return req.method(); }
/** * Creates a new {@link CsrfHandler} handler and use the given name to save the token in the * {@link Session} and or extract the token from incoming requests. * * @param name Token's name. */ public CsrfHandler(final String name) { this.name = requireNonNull(name, "Name is required."); tokenGen(req -> UUID.randomUUID().toString()); requireTokenOn(req -> REQUIRE_ON.contains(req.method())); }
@Override public void handle(final Request req, final Response rsp) throws Exception { if (!rsp.header(ALLOW).isSet()) { Set<String> allow = new LinkedHashSet<>(); Set<String> methods = new LinkedHashSet<>(Route.METHODS); String path = req.path(); methods.remove(req.method()); for (String method : methods) { routes.stream() .filter(route -> route.matches(method, path, MediaType.all, MediaType.ALL).isPresent()) .forEach(route -> allow.add(route.method())); } rsp.header(ALLOW, Joiner.on(SEP).join(allow)) .length(0) .status(Status.OK); } }
sb.append(BL).append(df.apply(timestamp)).append(BR); sb.append(SP); sb.append(Q).append(req.method()); sb.append(SP); sb.append(req.path());
req.method(), req.path(), req.route().print(6), err); rsp.type(MediaType.html).send(writer.toString());
@Override public void handle(final Request req, final Response rsp, final Err ex) throws Throwable { log.error("execution of: {}{} resulted in exception\nRoute:\n{}\n\nStacktrace:", req.method(), req.path(), req.route().print(6), ex); Config conf = req.require(Config.class); boolean stackstrace = Try.apply(() -> conf.getBoolean("err.stacktrace")) .orElse(req.require(Env.class).name().equals("dev")); rsp.send( Results .when(MediaType.html, () -> Results.html(VIEW).put("err", ex.toMap(stackstrace))) .when(MediaType.all, () -> ex.toMap(stackstrace))); }
private void preflight(final Cors cors, final Request req, final Response rsp, final String origin) { /** * Allowed method */ boolean allowMethod = req.header(AC_REQUEST_METHOD).toOptional() .map(cors::allowMethod) .orElse(false); if (!allowMethod) { return; } /** * Allowed headers */ List<String> headers = req.header(AC_REQUEST_HEADERS).toOptional().map(header -> Splitter.on(',').trimResults().omitEmptyStrings().splitToList(header) ).orElse(Collections.emptyList()); if (!cors.allowHeaders(headers)) { return; } /** * Allowed methods */ rsp.header(AC_ALLOW_METHODS, join(cors.allowedMethods())); List<String> allowedHeaders = cors.anyHeader() ? headers : cors.allowedHeaders(); rsp.header(AC_ALLOW_HEADERS, join(allowedHeaders));