|
6 | 6 | import java.util.HashMap; |
7 | 7 | import java.util.List; |
8 | 8 | import java.util.Map; |
| 9 | +import java.util.UUID; |
| 10 | +import java.util.concurrent.ConcurrentHashMap; |
9 | 11 | import java.util.function.Predicate; |
10 | 12 | import java.util.stream.Collectors; |
11 | 13 |
|
@@ -59,6 +61,22 @@ public class HttpServer { |
59 | 61 |
|
60 | 62 | private final WeakReference<ServerController> context; |
61 | 63 |
|
| 64 | + public class RequestInfo { |
| 65 | + public final String method; |
| 66 | + public final String path; |
| 67 | + public final String ip; |
| 68 | + public final long timestamp; |
| 69 | + |
| 70 | + public RequestInfo(String method, String path, String ip, long timestamp) { |
| 71 | + this.method = method; |
| 72 | + this.path = path; |
| 73 | + this.ip = ip; |
| 74 | + this.timestamp = timestamp; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + private final Map<String, RequestInfo> activeRequests = new ConcurrentHashMap<>(); |
| 79 | + |
62 | 80 | public HttpServer(WeakReference<ServerController> context) { |
63 | 81 | this.context = context; |
64 | 82 |
|
@@ -91,6 +109,21 @@ public HttpServer(WeakReference<ServerController> context) { |
91 | 109 | }); |
92 | 110 | }); |
93 | 111 |
|
| 112 | + app.before(ctx -> { |
| 113 | + String reqId = UUID.randomUUID().toString(); |
| 114 | + ctx.attribute("reqId", reqId); |
| 115 | + activeRequests.put(reqId, new RequestInfo( |
| 116 | + ctx.method().name(), ctx.path(), ctx.ip(), System.currentTimeMillis())); |
| 117 | + }); |
| 118 | + |
| 119 | + // Remove when request finishes |
| 120 | + app.after(ctx -> { |
| 121 | + String reqId = ctx.attribute("reqId"); |
| 122 | + if (reqId != null) { |
| 123 | + activeRequests.remove(reqId); |
| 124 | + } |
| 125 | + }); |
| 126 | + |
94 | 127 | Log.info("Http server created: " + this); |
95 | 128 | } |
96 | 129 |
|
@@ -431,6 +464,8 @@ public void init() { |
431 | 464 | .toList())) |
432 | 465 | .toList()); |
433 | 466 |
|
| 467 | + data.put("activeRequest", activeRequests.values()); |
| 468 | + |
434 | 469 | var maps = new ArrayList<HashMap<String, String>>(); |
435 | 470 | Vars.maps.all().forEach(map -> { |
436 | 471 | var tags = new HashMap<String, String>(); |
|
0 commit comments