当前位置: 首页>>代码示例>>C#>>正文


C# Session.OverrideRequest方法代码示例

本文整理汇总了C#中Fiddler.Session.OverrideRequest方法的典型用法代码示例。如果您正苦于以下问题:C# Session.OverrideRequest方法的具体用法?C# Session.OverrideRequest怎么用?C# Session.OverrideRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fiddler.Session的用法示例。


在下文中一共展示了Session.OverrideRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
        }
开发者ID:bradrees,项目名称:HttpRules,代码行数:78,代码来源:HttpsEverywhereAction.cs


注:本文中的Fiddler.Session.OverrideRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。