public void ReplaceBody(RequestPostData data) { if (!this.FilterContainer.HasFilters) { return; } string value = data.Body; int iIndexOffset = 0; foreach (var filter in this.FilterContainer.Filters) { if (filter.Type != FilterType.Body && filter.Type != FilterType.HeaderAndBody) { continue; } Match m = Regex.Match(value, filter.Regex); if (!m.Success) { continue; } this.ApplyManipulations(m, ref value, ref iIndexOffset, filter.Manipulations); } data.Body = value; }
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 // } }
private static async Task SendRequest(RequestPostData request) { using (HttpClient client = new HttpClient(new HttpClientHandler() { UseProxy = false, CookieContainer = request.Cookies })) { try { await client.SendAsync(request.HttpMessage); } catch (Exception ex) { Log(LogMessageType.Error, "Request could not be send: {0}", ex.GetFullMessage()); } } }
public RequestPostData(RequestPostData data) { this.Uri = data.Uri; this.Header = new Dictionary <string, string>(data.Header.Count); foreach (KeyValuePair <string, string> headerEntry in data.Header) { this.Header.Add(headerEntry.Key, headerEntry.Value); } this.NonSettableHeader = new Dictionary <string, string>(); //Not of interest anymore - Also reduces Log output procudes from FiddlerEngine this.Body = data.Body; this.BodyEncoding = data.BodyEncoding; this.HttpMessage = new HttpRequestMessage(HttpMethod.Post, data.Uri); this.Cookies = new CookieContainer(data.Cookies.Count); foreach (Cookie cookie in data.Cookies.GetCookies(this.Uri)) { this.Cookies.Add(data.Uri, new Cookie(cookie.Name, cookie.Value)); } }
public void ReplaceHeader(RequestPostData data) { if (!this.FilterContainer.HasFilters) { return; } int iIndexOffset = 0; Dictionary <string, string> newHeaders = new Dictionary <string, string>(data.Header.Count); foreach (KeyValuePair <string, string> headerEntry in data.Header) { string value = string.Format("{0}: {1}", headerEntry.Key, headerEntry.Value); foreach (var filter in this.FilterContainer.Filters) { if (filter.Type != FilterType.Header && filter.Type != FilterType.HeaderAndBody) { continue; } Match m = Regex.Match(value, filter.Regex); if (!m.Success) { continue; } this.ApplyManipulations(m, ref value, ref iIndexOffset, filter.Manipulations); } string[] newHeaderValues = value.Split(new char[] { ':' }, 2); if (newHeaderValues.Length == 2) { newHeaders.Add(newHeaderValues[0].Trim(), newHeaderValues[1].Trim()); } else { newHeaders.Add(headerEntry.Key, headerEntry.Value); } } data.Header.Clear(); data.Header = newHeaders; iIndexOffset = 0; foreach (Cookie cookie in data.Cookies.GetCookies(data.Uri)) { string value = string.Format("{0}={1}", cookie.Name, cookie.Value); foreach (var filter in this.FilterContainer.Filters) { if (filter.Type != FilterType.Header && filter.Type != FilterType.HeaderAndBody) { continue; } Match m = Regex.Match(value, filter.Regex); if (!m.Success) { continue; } this.ApplyManipulations(m, ref value, ref iIndexOffset, filter.Manipulations); } string[] newCookieValues = value.Split(new char[] { '=' }, 2); if (newCookieValues.Length == 2) { cookie.Name = newCookieValues[0]; cookie.Value = newCookieValues[1]; } } }