@Override public String getMethod() { return request.getMethod().name(); }
public void main(RakamHttpRequest request) { if (!request.getDecoderResult().isSuccess()) { sendError(request, BAD_REQUEST); return; } if (request.getMethod() != GET) { sendError(request, NOT_FOUND); return; } final String uri = request.path(); int idx = uri.indexOf("/static/"); File file; if (idx > -1) { final String path = sanitizeUri(uri); if (path == null) { sendError(request, FORBIDDEN); return; } file = new File(path); } else { file = new File(directory.getPath(), "index.html"); } sendFile(request, file); }
public Map<String, String> getActiveRequests() { Map<String, Holder> builder = new HashMap<>(); long l = System.currentTimeMillis(); httpServer.processingRequests.entrySet().stream() .forEach(r -> builder. compute(r.getKey().getMethod().name() + ":" + r.getKey().getUri(), (k, v) -> (v == null ? new Holder(r.getValue()) : v.add(l - r.getValue())))); return builder.entrySet().stream() .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toString())); }
public void handle(RakamHttpRequest request) { String path = cleanPath(request.path()); int lastIndex = path.length() - 1; if (lastIndex > 0 && path.charAt(lastIndex) == '/') { path = path.substring(0, lastIndex); } HttpMethod method = request.getMethod(); final HttpRequestHandler handler = routes.get(new PatternBinding(method, path)); if (handler != null) { if (handler instanceof WebSocketService) { request.context().attr(PATH).set(path); } handler.handle(request); } else { for (Map.Entry<PatternBinding, HttpRequestHandler> prefixRoute : prefixRoutes) { if (method.equals(prefixRoute.getKey().method) && path.startsWith(prefixRoute.getKey().pattern)) { prefixRoute.getValue().handle(request); return; } } noMatch.handle(request); } }