private static bool FiltrarPedidos(Fiddler.Session req)
        {
            if (req.HostnameIs("www.google-analytics.com"))
            {
                if (Descartados == null)
                {
                    Descartados = new Dictionary <string, List <int> >();
                }

                if (Descartados.ContainsKey("www.google-analytics.com"))
                {
                    Descartados["www.google-analytics.com"].Add(req.id);
                }
                else
                {
                    Descartados.Add("www.google-analytics.com", new List <int> {
                        req.id
                    });
                }

                return(true);
            }

            foreach (var host in Hosts.Where(host => req.hostname.EndsWith(host)))
            {
                if (Descartados == null)
                {
                    Descartados = new Dictionary <string, List <int> >();
                }

                if (Descartados.ContainsKey(host))
                {
                    Descartados[host].Add(req.id);
                }
                else
                {
                    Descartados.Add(host, new List <int> {
                        req.id
                    });
                }

                return(true);
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// 根据配置处理请求
        /// </summary>
        /// <param name="session"></param>
        public void ReplaceRequest(Fiddler.Session session)
        {
            //不采用,则不处理
            if (!chkEnabled.Checked)
            {
                return;
            }

            // 如果是代理请求,则不做处理
            if (session.HTTPMethodIs("CONNECT"))
            {
                session["X-ReplyWithTunnel"] = "Fake for HTTPS Tunnel";
                return;
            }

            var config = GetRules();

            if (config.groups == null || config.groups.Count == 0)
            {
                return;
            }
            foreach (var g in config.groups)
            {
                if (g.rules == null || g.rules.Count == 0 || !g.enabled)
                {
                    continue;
                }
                foreach (var r in g.rules)
                {
                    if (!r.enabled)
                    {
                        continue;
                    }
                    //如果是正则,且命中,则处理
                    if (r.match.StartsWith("regex:", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var s   = System.Text.RegularExpressions.Regex.Replace(r.match, "^regex:", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            var reg = new System.Text.RegularExpressions.Regex(s, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            if (reg.IsMatch(session.fullUrl))
                            {
                                Utils.ResetSession(r, session, reg);
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            Utils.FiddlerLog("表示式" + r.match + "不正确," + ex.Message);
                            return;
                        }
                    }
                    //hostname
                    else if (session.HostnameIs(r.match) || session.host == r.match)
                    {
                        Utils.ResetSession(r, session);
                        return;
                    }
                    //请求完全等于,也命中
                    else if (session.fullUrl.Equals(r.match, StringComparison.OrdinalIgnoreCase))
                    {
                        Utils.ResetSession(r, session);
                        return;
                    }
                }
            }
        }