Ejemplo n.º 1
0
        private void OnRequestWillBeSent(RequestWillBeSentResponse e)
        {
            var redirectChain = new List <Request>();

            if (_protocolRequestInterceptionEnabled)
            {
                // All redirects are handled in requestIntercepted.
                if (e.RedirectResponse != null)
                {
                    return;
                }
                var requestHash    = e.Request.Hash;
                var interceptionId = _requestHashToInterceptionIds.FirstValue(requestHash);
                if (interceptionId != null && _interceptionIdToRequest.TryGetValue(interceptionId, out var request))
                {
                    request.RequestId = e.RequestId;
                    _requestIdToRequest[e.RequestId] = request;
                    _requestHashToInterceptionIds.Delete(requestHash, interceptionId);
                }
                else
                {
                    _requestHashToRequestIds.Add(requestHash, e.RequestId);
                }
                return;
            }

            if (e.RedirectResponse != null && _requestIdToRequest.ContainsKey(e.RequestId))
            {
                var request = _requestIdToRequest[e.RequestId];
                // If we connect late to the target, we could have missed the requestWillBeSent event.
                HandleRequestRedirect(
                    request,
                    e.RedirectResponse.Status,
                    e.RedirectResponse.Headers,
                    e.RedirectResponse.FromDiskCache,
                    e.RedirectResponse.FromServiceWorker,
                    e.RedirectResponse.SecurityDetails);

                redirectChain = request.RedirectChainList;
            }
            var isNavigationRequest = e.RequestId == e.LoaderId && e.Type == ResourceType.Document;

            HandleRequestStart(e.RequestId, null, e.Request.Url, isNavigationRequest, e.Type, e.Request, e.FrameId, redirectChain);
        }
Ejemplo n.º 2
0
        private void OnRequestWillBeSent(RequestWillBeSentResponse e)
        {
            if (_protocolRequestInterceptionEnabled)
            {
                // All redirects are handled in requestIntercepted.
                if (e.RedirectResponse != null)
                {
                    return;
                }
                string requestHash    = e.Request.Hash;
                var    interceptionId = _requestHashToInterceptionIds.FirstValue(requestHash);
                if (interceptionId != null && _interceptionIdToRequest.TryGetValue(interceptionId, out var request))
                {
                    request.RequestId = e.RequestId;
                    _requestIdToRequest[e.RequestId] = request;
                    _requestHashToInterceptionIds.Delete(requestHash, interceptionId);
                }
                else
                {
                    _requestHashToRequestIds.Add(requestHash, e.RequestId);
                }
                return;
            }

            if (e.RedirectResponse != null && _requestIdToRequest.ContainsKey(e.RequestId))
            {
                var request = _requestIdToRequest[e.RequestId];
                // If we connect late to the target, we could have missed the requestWillBeSent event.
                HandleRequestRedirect(
                    request,
                    e.RedirectResponse.Status,
                    e.RedirectResponse.Headers,
                    false,
                    e.RedirectResponse.SecurityDetails);
            }

            HandleRequestStart(e.RequestId, null, e.Request.Url, e.Type, e.Request, e.FrameId);
        }