Ejemplo n.º 1
0
        /// <summary>
        /// 重置请求response
        /// </summary>
        /// <param name="session"></param>
        /// <param name="status"></param>
        /// <param name="contentType"></param>
        public static void ResetResponse(Fiddler.Session session, int status = 200, string contentType = "text/html; charset=utf-8")
        {
            //伪造response
            session.utilCreateResponseAndBypassServer();
            session.oResponse.headers.SetStatus(status, "By jmFidExt");

            session.oResponse["Content-Type"] = contentType;

            session.oResponse["Date"] = DateTime.Now.ToUniversalTime().ToString("r");
        }
Ejemplo n.º 2
0
        internal static void Handle(Fiddler.Session Sess)
        {
            Session  IrSe = new Session(Sess);
            Response Res  = new Response("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK");

            Res.Headers.Set("Access-Control-Allow-Origin", "*");

            string ApiUrl     = IrSe.Request.UrlPath.Substring(14);
            bool   MatchFound = false;

            if (ApiUrl.StartsWith("core/", StringComparison.OrdinalIgnoreCase))
            {
                ApiUrl = ApiUrl.Substring(5);
                if (CoreCallHandlers.ContainsKey(ApiUrl))
                {
                    MatchFound = true;
                    try
                    {
                        CoreCallHandlers[ApiUrl](IrSe.Request, Res);
                    }
                    catch (Exception Exp)
                    {
                        Res.BodyString = string.Format("Error executing API call.\r\nError details:\r\n{0}\r\n{1}", Exp.Message, Exp.StackTrace);
                    }
                }
            }
            else if (ApiUrl.StartsWith("custom/", StringComparison.OrdinalIgnoreCase))
            {
                ApiUrl = ApiUrl.Substring(7);
                if (CustomCallHandlers.ContainsKey(ApiUrl))
                {
                    MatchFound = true;
                    try
                    {
                        CustomCallHandlers[ApiUrl](IrSe.Request, Res);
                    }
                    catch (Exception Exp)
                    {
                        Res.BodyString = string.Format("Error executing API call.\r\nError details:\r\n{0}\r\n{1}", Exp.Message, Exp.StackTrace);
                    }
                }
            }
            if (!MatchFound)
            {
                StringBuilder SB = new StringBuilder();
                SB.AppendLine("No API call handler registered for this URL");
                SB.AppendLine();
                SB.AppendLine("The following are the registered URLs:");
                foreach (string Url in CoreCallHandlers.Keys)
                {
                    SB.Append(CoreApiUrlStart); SB.AppendLine(Url);
                }
                Res.BodyString = SB.ToString();
                foreach (string Url in CustomCallHandlers.Keys)
                {
                    SB.Append(CustomApiUrlStart); SB.AppendLine(Url);
                }
                Res.BodyString = SB.ToString();
            }


            //switch (ApiUrl)
            //{
            //    case("LogRangeStart"):
            //        ProxyLogRangeStart = Config.LastProxyLogId;
            //        ProxyLogRangeEnd = 0;
            //        break;
            //    case ("LogRangeEnd"):
            //        ProxyLogRangeEnd = Config.LastProxyLogId;
            //        break;
            //    case ("ScanLogRange"):
            //        break;
            //    default:
            //        if (CustomCallHandlers.ContainsKey(ApiUrl))
            //        {
            //            CustomCallHandlers[ApiUrl](IrSe.Request, Res);
            //        }
            //        else
            //        {
            //        }
            //        break;
            //}
            Sess.utilCreateResponseAndBypassServer();
            Sess.oResponse.headers.AssignFromString(Res.GetHeadersAsString());
            Sess.responseBodyBytes = Res.BodyArray;
        }