/** * An alias for {@link HttpPredicate#get} prefix ([prefix]/**), useful for file system * mapping. * <p> * Creates a {@link Predicate} based on a URI template filtering . * <p> * This will listen for WebSocket Method. * * @return The new {@link Predicate}. * * @see Predicate */ public static Predicate<HttpServerRequest> prefix(String prefix) { return prefix(prefix, HttpMethod.GET); }
/** * An alias for {@link HttpPredicate#get} prefix ([prefix]/**), useful for file system * mapping. * <p> * Creates a {@link Predicate} based on a URI template filtering . * <p> * This will listen for WebSocket Method. * * @return The new {@link Predicate}. * * @see Predicate */ public static Predicate<HttpServerRequest> prefix(String prefix) { return prefix(prefix, HttpMethod.GET); }
@Override public HttpServerRoutes directory(String uri, Path directory, Function<HttpServerResponse, HttpServerResponse> interceptor) { Objects.requireNonNull(directory, "directory"); return route(HttpPredicate.prefix(uri), (req, resp) -> { String prefix = URI.create(req.uri()) .getPath() .replaceFirst(uri, ""); if(prefix.charAt(0) == '/'){ prefix = prefix.substring(1); } Path p = directory.resolve(prefix); if (Files.isReadable(p)) { if (interceptor != null) { return interceptor.apply(resp) .sendFile(p); } return resp.sendFile(p); } return resp.sendNotFound(); }); }
@Override public HttpServerRoutes directory(String uri, Path directory, Function<HttpServerResponse, HttpServerResponse> interceptor) { Objects.requireNonNull(directory, "directory"); return route(HttpPredicate.prefix(uri), (req, resp) -> { String prefix = URI.create(req.uri()) .getPath() .replaceFirst(uri, ""); if(prefix.charAt(0) == '/'){ prefix = prefix.substring(1); } Path p = directory.resolve(prefix); if (Files.isReadable(p)) { if (interceptor != null) { return interceptor.apply(resp) .sendFile(p); } return resp.sendFile(p); } return resp.sendNotFound(); }); }