com.microsoft.playwright.impl.WebSocketRouter Maven / Gradle / Ivy
package com.microsoft.playwright.impl;
import com.google.gson.JsonObject;
import com.microsoft.playwright.WebSocketRoute;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class WebSocketRouter {
private List routes = new ArrayList<>();
private static class RouteInfo {
final UrlMatcher matcher;
private final Consumer handler;
RouteInfo(UrlMatcher matcher, Consumer handler) {
this.matcher = matcher;
this.handler = handler;
}
void handle(WebSocketRouteImpl route) {
handler.accept(route);
route.afterHandle();
}
}
void add(UrlMatcher matcher, Consumer handler) {
routes.add(0, new RouteInfo(matcher, handler));
}
boolean handle(WebSocketRouteImpl route) {
for (RouteInfo routeInfo: routes) {
if (routeInfo.matcher.test(route.url())) {
routeInfo.handle(route);
return true;
}
}
return false;
}
JsonObject interceptionPatterns() {
List matchers = routes.stream().map(r -> r.matcher).collect(Collectors.toList());
return Utils.interceptionPatterns(matchers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy