@Override public String getPath() { return request.getPath(); }
private String currentUriWithTrailingSlash(Context context) { Request request = context.getRequest(); String redirectUri = "/" + request.getPath() + "/"; String query = request.getQuery(); if (!query.isEmpty()) { redirectUri += "?" + query; } return redirectUri; }
private void maybeSendFile(final Context context, final Path file, final int i) throws Exception { if (i == indexFiles.size()) { context.next(); } else { String name = indexFiles.get(i); final Path indexFile = file.resolve(name); readAttributes(indexFile, cacheMetadata, attributes -> { if (attributes != null && attributes.isRegularFile()) { String path = context.getRequest().getPath(); if (path.endsWith("/") || path.isEmpty()) { sendFile(context, indexFile, attributes); } else { context.redirect(currentUriWithTrailingSlash(context)); } } else { maybeSendFile(context, file, i + 1); } }); } }