@@ -69,8 +69,6 @@ private static final Map<EventType, String> eventSubscriptions() {
6969 }
7070 private final ListenerCollection <EventType > listeners = new ListenerCollection <>(eventSubscriptions (), this );
7171 final TimeoutSettings timeoutSettings = new TimeoutSettings ();
72- Path videosDir ;
73- URL baseUrl ;
7472 final Map <String , HarRecorder > harRecorders = new HashMap <>();
7573
7674 static class HarRecorder {
@@ -103,19 +101,25 @@ enum EventType {
103101 request .timeoutSettings = timeoutSettings ;
104102 clock = new ClockImpl (this );
105103 closePromise = new WaitableEvent <>(listeners , EventType .CLOSE );
104+ }
106105
106+ Path videosDir () {
107+ JsonObject recordVideo = initializer .getAsJsonObject ("options" ).getAsJsonObject ("recordVideo" );
108+ if (recordVideo == null ) {
109+ return null ;
110+ }
111+ return Paths .get (recordVideo .get ("dir" ).getAsString ());
112+ }
113+
114+ URL baseUrl () {
107115 JsonElement url = initializer .getAsJsonObject ("options" ).get ("baseURL" );
108116 if (url != null ) {
109117 try {
110- this . baseUrl = new URL (url .getAsString ());
118+ return new URL (url .getAsString ());
111119 } catch (MalformedURLException e ) {
112120 }
113121 }
114-
115- JsonObject recordVideo = initializer .getAsJsonObject ("options" ).getAsJsonObject ("recordVideo" );
116- if (recordVideo != null ) {
117- this .videosDir = Paths .get (recordVideo .get ("dir" ).getAsString ());
118- }
122+ return null ;
119123 }
120124
121125 void setRecordHar (Path path , HarContentPolicy policy ) {
@@ -481,7 +485,7 @@ public APIRequestContextImpl request() {
481485
482486 @ Override
483487 public void route (String url , Consumer <Route > handler , RouteOptions options ) {
484- route (UrlMatcher .forGlob (baseUrl , url , this .connection .localUtils , false ), handler , options );
488+ route (UrlMatcher .forGlob (baseUrl () , url , this .connection .localUtils , false ), handler , options );
485489 }
486490
487491 @ Override
@@ -503,7 +507,7 @@ public void routeFromHAR(Path har, RouteFromHAROptions options) {
503507 recordIntoHar (null , har , options , null );
504508 return ;
505509 }
506- UrlMatcher matcher = UrlMatcher .forOneOf (baseUrl , options .url , this .connection .localUtils , false );
510+ UrlMatcher matcher = UrlMatcher .forOneOf (baseUrl () , options .url , this .connection .localUtils , false );
507511 HARRouter harRouter = new HARRouter (connection .localUtils , har , options .notFound );
508512 onClose (context -> harRouter .dispose ());
509513 route (matcher , route -> harRouter .handle (route ), null );
@@ -518,7 +522,7 @@ private void route(UrlMatcher matcher, Consumer<Route> handler, RouteOptions opt
518522
519523 @ Override
520524 public void routeWebSocket (String url , Consumer <WebSocketRoute > handler ) {
521- routeWebSocketImpl (UrlMatcher .forGlob (baseUrl , url , this .connection .localUtils , true ), handler );
525+ routeWebSocketImpl (UrlMatcher .forGlob (baseUrl () , url , this .connection .localUtils , true ), handler );
522526 }
523527
524528 @ Override
@@ -658,7 +662,7 @@ public void unrouteAll() {
658662
659663 @ Override
660664 public void unroute (String url , Consumer <Route > handler ) {
661- unroute (UrlMatcher .forGlob (this .baseUrl , url , this .connection .localUtils , false ), handler );
665+ unroute (UrlMatcher .forGlob (this .baseUrl () , url , this .connection .localUtils , false ), handler );
662666 }
663667
664668 @ Override
0 commit comments