本文整理汇总了C#中Fiddler.Session.RedirectSession方法的典型用法代码示例。如果您正苦于以下问题:C# Session.RedirectSession方法的具体用法?C# Session.RedirectSession怎么用?C# Session.RedirectSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fiddler.Session
的用法示例。
在下文中一共展示了Session.RedirectSession方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeforeRequest
public bool BeforeRequest(Session session, Rule rule)
{
// HTTPS Everywhere: https://www.eff.org/https-everywhere
if (!session.isHTTPS && session.port != 443)
{
var host = new Uri(session.fullUrl).Host;
foreach (var ruleset in Rulesets)
{
if (ruleset.MatchRule != null)
{
if (!ruleset.MatchRule.IsMatch(session.fullUrl))
{
continue;
}
}
if (ruleset.Exclusions.Any(ex => ex.IsMatch(session.fullUrl)))
{
continue;
}
if (ruleset.Targets.Any() && !ruleset.Targets.Any(t => t.IsMatch(host)))
{
continue;
}
foreach (var rulesetRule in ruleset.Rule)
{
if (!rulesetRule.From.IsMatch(session.fullUrl))
{
continue;
}
var secureUrl = rulesetRule.From.Replace(session.fullUrl, rulesetRule.To);
// So here we are checking for a redirect loop, if we get 10 redirects in a row in 30 seconds then we need to drop back to HTTP.
lock (RedirectLocker)
{
if (RedirectCounter.Any() && RedirectCounter.Last().Item1 == session.fullUrl)
{
if (RedirectCounter.Count > 5 && (RedirectCounter.Max(t => t.Item3) - RedirectCounter.Min(t => t.Item3)).TotalSeconds < 30)
{
RuleLog.Current.AddRule(
rule,
session,
String.Format("HttpsEverywhere (Failed): {0} ({1})", ruleset.Name, session.hostname));
return true;
}
}
else
{
RedirectCounter.Clear();
}
RedirectCounter.Add(Tuple.Create(session.fullUrl, secureUrl, DateTime.UtcNow));
}
if (this.FakeHttps) // BUG: This doesn't really work at the moment.
{
return !session.OverrideRequest(secureUrl);
}
rule.ResponseLog.FireEvent(session, new ResponseSummaryEventArgs { FullUrl = session.fullUrl, Referer = (session.oRequest["Referer"].HasValue() ? session.oRequest["Referer"] : "None"), ResponseCode = 302, ResponseCodeText = "302 Moved to SSL Connection", Length = 0 });
session.RedirectSession(secureUrl, false);
RuleLog.Current.AddRule(
rule,
session,
String.Format("HttpsEverywhere: {0} ({1})", ruleset.Name, session.hostname));
return false;
}
}
}
return true;
}
示例2: OnResponse
/// <summary>
/// Action to run once the response has been received.
/// </summary>
/// <param name = "session">The fiddler session object.</param>
/// <param name = "rule">The current rule being executed.</param>
/// <returns>
/// false to terminate any further response actions, or true to continue.
/// </returns>
public bool OnResponse(Session session, Rule rule)
{
if (session.oResponse.headers[ResponseHeaderName].HasValue())
{
var headerElements = ParseResponseHeader(session.oResponse.headers[ResponseHeaderName]);
var altUrl = GetAlternateContentUrl(headerElements, new Uri(session.fullUrl));
if (this.IsBelowRestrictedAge(headerElements))
{
if (altUrl.HasValue())
{
session.RedirectSession(altUrl, false);
}
else
{
session.oRequest.FailSession(403, "Restricted By Age", "Request blocked due to the rule: " + rule.Name);
return false;
}
}
else if (this.IsBelowRecommendedAge(headerElements))
{
if (altUrl.HasValue())
{
session.RedirectSession(altUrl, false);
}
}
}
return true;
}