@@ -17,8 +17,7 @@ internal class NetworkManager
1717 private readonly ConcurrentDictionary < string , Request > _requestIdToRequest = new ConcurrentDictionary < string , Request > ( ) ;
1818 private readonly ConcurrentDictionary < string , RequestWillBeSentPayload > _requestIdToRequestWillBeSentEvent =
1919 new ConcurrentDictionary < string , RequestWillBeSentPayload > ( ) ;
20- private readonly MultiMap < string , string > _requestHashToRequestIds = new MultiMap < string , string > ( ) ;
21- private readonly MultiMap < string , string > _requestHashToInterceptionIds = new MultiMap < string , string > ( ) ;
20+ private readonly ConcurrentDictionary < string , string > _requestIdToInterceptionId = new ConcurrentDictionary < string , string > ( ) ;
2221 private readonly ILogger _logger ;
2322 private Dictionary < string , string > _extraHTTPHeaders ;
2423 private bool _offine ;
@@ -245,19 +244,13 @@ private async Task OnRequestInterceptedAsync(RequestInterceptedResponse e)
245244 }
246245 }
247246
248- var requestHash = e . Request . Hash ;
249- var requestId = _requestHashToRequestIds . FirstValue ( requestHash ) ;
250- if ( requestId != null )
247+ if ( e . RequestId != null && _requestIdToRequestWillBeSentEvent . TryRemove ( e . RequestId , out var requestWillBeSentEvent ) )
251248 {
252- if ( _requestIdToRequestWillBeSentEvent . TryRemove ( requestId , out var requestWillBeSentEvent ) )
253- {
254- await OnRequestAsync ( requestWillBeSentEvent , e . InterceptionId ) ;
255- _requestHashToRequestIds . Delete ( requestHash , requestId ) ;
256- }
249+ await OnRequestAsync ( requestWillBeSentEvent , e . InterceptionId ) ;
257250 }
258251 else
259252 {
260- _requestHashToInterceptionIds . Add ( requestHash , e . InterceptionId ) ;
253+ _requestIdToInterceptionId [ e . RequestId ] = e . InterceptionId ;
261254 }
262255 }
263256
@@ -343,16 +336,12 @@ private async Task OnRequestWillBeSentAsync(RequestWillBeSentPayload e)
343336 // Request interception doesn't happen for data URLs with Network Service.
344337 if ( _protocolRequestInterceptionEnabled && ! e . Request . Url . StartsWith ( "data:" , StringComparison . InvariantCultureIgnoreCase ) )
345338 {
346- var requestHash = e . Request . Hash ;
347- var interceptionId = _requestHashToInterceptionIds . FirstValue ( requestHash ) ;
348- if ( interceptionId != null )
339+ if ( _requestIdToInterceptionId . TryRemove ( e . RequestId , out var interceptionId ) )
349340 {
350341 await OnRequestAsync ( e , interceptionId ) ;
351- _requestHashToInterceptionIds . Delete ( requestHash , interceptionId ) ;
352342 }
353343 else
354344 {
355- _requestHashToRequestIds . Add ( requestHash , e . RequestId ) ;
356345 // Under load, we may get to this section more than once
357346 _requestIdToRequestWillBeSentEvent . TryAdd ( e . RequestId , e ) ;
358347 }
0 commit comments