コード例 #1
0
        public static string GetRequestTriggerHighlighting(string Trigg, Request Req)
        {
            StringBuilder SB        = new StringBuilder();
            string        ReqHeader = Req.GetHeadersAsString();
            string        ReqBody   = Req.BodyString;

            List <string> AllTriggerVariations = new List <string>();

            AllTriggerVariations.Add(Trigg);
            if (!AllTriggerVariations.Contains(Request.PathPartEncode(Trigg)))
            {
                AllTriggerVariations.Add(Request.PathPartEncode(Trigg));
            }
            if (!AllTriggerVariations.Contains(QueryParameters.Encode(Trigg)))
            {
                AllTriggerVariations.Add(QueryParameters.Encode(Trigg));
            }
            if (!AllTriggerVariations.Contains(CookieParameters.Encode(Trigg)))
            {
                AllTriggerVariations.Add(CookieParameters.Encode(Trigg));
            }
            if (!AllTriggerVariations.Contains(HeaderParameters.Encode(Trigg)))
            {
                AllTriggerVariations.Add(HeaderParameters.Encode(Trigg));
            }

            try
            {
                List <string> HeaderAdjustments = GetHeaderVariations(Trigg, Req.Headers, ReqHeader);
                foreach (string HA in HeaderAdjustments)
                {
                    if (!AllTriggerVariations.Contains(HA))
                    {
                        AllTriggerVariations.Add(HA);
                    }
                }
            }
            catch { }

            List <string> HeaderTriggerVariations = new List <string>();


            foreach (string CurrentVariation in AllTriggerVariations)
            {
                if (!HeaderTriggerVariations.Contains(CurrentVariation) && ReqHeader.Contains(CurrentVariation))
                {
                    HeaderTriggerVariations.Add(CurrentVariation);
                }
            }
            ReqHeader = Highlighter.InsertHighlights(ReqHeader, HeaderTriggerVariations);

            ReqBody = GetRequestBodyHighlighting(ReqBody, Trigg);
            if (!ReqHeader.Contains("<i<hlg>>") && !ReqBody.Contains("<i<hlg>>"))
            {
                foreach (string TriggLine in Tools.SplitLines(Trigg))
                {
                    ReqBody = GetRequestBodyHighlighting(ReqBody, TriggLine);
                }
            }

            SB.Append(Highlighter.SnipHeaderSection(ReqHeader).TrimEnd());
            SB.AppendLine(); SB.AppendLine();
            SB.Append(Highlighter.SnipBodySection(ReqBody));
            return(SB.ToString().Replace("\n", "<i<br>>"));
        }