Exemplo n.º 1
0
        private static void HandleAfterSessionComplete(Session session)
        {
            if (!session.HTTPMethodIs("POST"))
            {
                return;
            }
            if (!FitsMask(session.oRequest.host, HostFilter))
            {
                return;
            }
            if (Replacer == null)
            {
                return;
            }

            Log(LogMessageType.Information, "Processing request to URL: '{0}'", session.fullUrl);

            string sHeader = "";

            foreach (var item in session.oRequest.headers)
            {
                sHeader += string.Format("{0}: {1}\n", item.Name, item.Value);
            }
            sHeader = sHeader.TrimEnd();

            Encoding bodyEnc = session.GetRequestBodyEncoding();
            string   sBody   = session.GetRequestBodyAsString();

            RequestPostData baseData = new RequestPostData(session.fullUrl, sHeader, sBody, bodyEnc);

            List <RequestPostData> requests = new List <RequestPostData>(Multiplicator);

            for (int i = 0; i < Multiplicator; i++)
            {
                RequestPostData newData = new RequestPostData(baseData);
                Replacer.ReplaceHeader(newData);
                Replacer.ReplaceBody(newData);
                newData.UpdateRequest();
                requests.Add(newData);
                baseData = newData;
            }

            ServicePointManager.ServerCertificateValidationCallback = null;

            Parallel.ForEach <RequestPostData>(requests, req =>
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                SendRequest(req);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            });

            //                foreach (RequestPostData data in _requests)
            //                {
            //#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            //                    SendRequest(data);
            //#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            //                }
        }