internal List <string> CompareHeaders(HTTPRequestHeaders left, HTTPRequestHeaders right) { var leftResult = string.Empty; var rightResult = string.Empty; var leftOnly = string.Empty; foreach (var head in left) { var sameInRight = right.FirstOrDefault(x => x.Name == head.Name); if (sameInRight == null) { leftOnly += head.Name + ":" + head.Value + Environment.NewLine; } else { if (head.Value != sameInRight.Value) { leftResult += head.Name + ":" + head.Value + Environment.NewLine; rightResult += sameInRight.Name + ":" + sameInRight.Value + Environment.NewLine; } right.Remove(sameInRight.Name); } } foreach (var head in right) { rightResult += head.Name + ":" + head.Value + Environment.NewLine; } return(new List <string> { leftResult + Environment.NewLine + leftOnly, rightResult }); }
/// <summary> /// Strips the configured Cookie / URL / POST parameters from our HTTP headers and body /// </summary> /// <param name="headers">Headers to search for Cookie and URL data</param> /// <param name="body">Body to search for POST data</param> /// <returns>True if request has been modified, False if request was not modified</returns> protected bool StripSessionFromRequest(HTTPRequestHeaders headers, ref byte[] body) { bool requestModified = false; // Strip our Cookie parameters if (headers["Cookie"] != null && authTab.CookieSelector.ParameterList.Count != 0) { foreach (string cookieName in authTab.CookieSelector.ParameterList) { Match match = Regex.Match(headers["Cookie"], String.Format(@"(\s*{0}=[^;]*;\s*)", cookieName), RegexOptions.Multiline); if (match.Success) { headers["Cookie"] = headers["Cookie"].Replace(match.Groups[1].Value, String.Empty); requestModified = true; } } if (headers["Cookie"].Trim() == String.Empty) { headers.Remove("Cookie"); } } // Strip our URL parameters if (headers.RequestPath.Contains("?") && authTab.URLParameterSelector.ParameterList.Count != 0) { foreach (string urlParameterName in authTab.URLParameterSelector.ParameterList) { Match match = Regex.Match(headers.RequestPath, String.Format(@"\?*({0}=[^&\s]*&*)", urlParameterName), RegexOptions.IgnoreCase); if (match.Success) { headers.RequestPath = headers.RequestPath.Replace(match.Groups[1].Value, String.Empty); requestModified = true; } } } // Strip our POST parameters if (body != null && body.Length != 0 && authTab.POSTParameterSelector.ParameterList.Count != 0) { string postParams = System.Text.ASCIIEncoding.ASCII.GetString(body); foreach (string postParameterName in authTab.POSTParameterSelector.ParameterList) { Match match = Regex.Match(postParams, String.Format(@"({0}=[^&\s]*&*)", postParameterName), RegexOptions.Multiline); if (match.Success) { postParams = postParams.Replace(match.Groups[1].Value, String.Empty); requestModified = true; } } body = System.Text.ASCIIEncoding.ASCII.GetBytes(postParams); headers["Content-Length"] = Convert.ToString(body.Length); } return requestModified; }
public Session SendRequest(HTTPRequestHeaders oHeaders, byte[] arrRequestBodyBytes, StringDictionary oNewFlags, EventHandler<StateChangeEventArgs> onStateChange) { if (oHeaders.ExistsAndContains("Fiddler-Encoding", "base64")) { oHeaders.Remove("Fiddler-Encoding"); if (!Utilities.IsNullOrEmpty(arrRequestBodyBytes)) { arrRequestBodyBytes = Convert.FromBase64String(Encoding.ASCII.GetString(arrRequestBodyBytes)); if (oNewFlags == null) { oNewFlags = new StringDictionary(); } oNewFlags["x-Builder-FixContentLength"] = "CFE-required"; } } if (oHeaders.Exists("Fiddler-Host")) { if (oNewFlags == null) { oNewFlags = new StringDictionary(); } oNewFlags["x-OverrideHost"] = oHeaders["Fiddler-Host"]; oNewFlags["X-IgnoreCertCNMismatch"] = "Overrode HOST"; oHeaders.Remove("Fiddler-Host"); } if ((oNewFlags != null) && oNewFlags.ContainsKey("x-Builder-FixContentLength")) { if ((arrRequestBodyBytes != null) && !oHeaders.ExistsAndContains("Transfer-Encoding", "chunked")) { if (!Utilities.HTTPMethodAllowsBody(oHeaders.HTTPMethod) && (arrRequestBodyBytes.Length == 0)) { oHeaders.Remove("Content-Length"); } else { oHeaders["Content-Length"] = arrRequestBodyBytes.LongLength.ToString(); } } else { oHeaders.Remove("Content-Length"); } } Session session = new Session((HTTPRequestHeaders) oHeaders.Clone(), arrRequestBodyBytes); session.SetBitFlag(SessionFlags.RequestGeneratedByFiddler, true); if (onStateChange != null) { session.OnStateChanged += onStateChange; } if ((oNewFlags != null) && (oNewFlags.Count > 0)) { foreach (DictionaryEntry entry in oNewFlags) { session.oFlags[(string) entry.Key] = oNewFlags[(string) entry.Key]; } } session.ExecuteUponAsyncRequest(); return session; }