@@ -59,7 +59,7 @@ public abstract class Network<AUTHREQUIRED, REQUESTPAUSED> {
59
59
60
60
private final Map <Predicate <URI >, Supplier <Credentials >> authHandlers = new LinkedHashMap <>();
61
61
private final Filter defaultFilter = next -> next ::execute ;
62
- private Filter filter = defaultFilter ;
62
+ private volatile Filter filter = defaultFilter ;
63
63
protected final DevTools devTools ;
64
64
65
65
private final AtomicBoolean networkInterceptorRegistered = new AtomicBoolean ();
@@ -73,7 +73,9 @@ public void disable() {
73
73
devTools .send (disableFetch ());
74
74
devTools .send (enableNetworkCaching ());
75
75
76
- authHandlers .clear ();
76
+ synchronized (authHandlers ) {
77
+ authHandlers .clear ();
78
+ }
77
79
filter = defaultFilter ;
78
80
}
79
81
@@ -128,7 +130,9 @@ public void addAuthHandler(
128
130
Require .nonNull ("URI predicate" , whenThisMatches );
129
131
Require .nonNull ("Credentials" , useTheseCredentials );
130
132
131
- authHandlers .put (whenThisMatches , useTheseCredentials );
133
+ synchronized (authHandlers ) {
134
+ authHandlers .put (whenThisMatches , useTheseCredentials );
135
+ }
132
136
133
137
prepareToInterceptTraffic ();
134
138
}
@@ -250,11 +254,13 @@ public void prepareToInterceptTraffic() {
250
254
protected Optional <Credentials > getAuthCredentials (URI uri ) {
251
255
Require .nonNull ("URI" , uri );
252
256
253
- return authHandlers .entrySet ().stream ()
254
- .filter (entry -> entry .getKey ().test (uri ))
255
- .map (Map .Entry ::getValue )
256
- .map (Supplier ::get )
257
- .findFirst ();
257
+ synchronized (authHandlers ) {
258
+ return authHandlers .entrySet ().stream ()
259
+ .filter (entry -> entry .getKey ().test (uri ))
260
+ .map (Map .Entry ::getValue )
261
+ .map (Supplier ::get )
262
+ .findFirst ();
263
+ }
258
264
}
259
265
260
266
protected HttpMethod convertFromCdpHttpMethod (String method ) {
0 commit comments