Пример #1
0
    private void processRuleForSession(Session oSession, String ruleStr)
    {
        oSession.utilDecodeResponse();
        // check 304
        if (oSession.responseCode.ToString() == "304")
        {
            if (MessageBox.Show("This request session's ResponseCode is 304, means no data responded!\nContinue to Edit?", "Fedit Warning:",
                MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return;
        }

        // check encode type
        FiddlerApplication.Log.LogString(oSession.GetResponseBodyEncoding().ToString());

        String tmp_filetype;
        if (fileType.ContainsKey(oSession.oResponse.MIMEType.ToString()))
        {
            tmp_filetype = (String)fileType[oSession.oResponse.MIMEType.ToString()];
        }
        else
        {
            Stack<string> ext = new Stack<string>(oSession.fullUrl.Split(new string[] { "." }, StringSplitOptions.None));
            tmp_filetype = "." + Regex.Replace(ext.Pop(), @"([a-zA-Z\d]+?)[^a-zA-Z\d].+", "$1");
        }
        String escaped_url = System.Uri.EscapeDataString(oSession.fullUrl);
        String tmp_filename = escaped_url.Substring(0, escaped_url.Length < 150 ? escaped_url.Length : 150) + tmp_filetype;
        String fedit_file = fedit_path + "\\" + tmp_filename;
        FiddlerApplication.Log.LogString("Saving url \"" + oSession.fullUrl + "\" to temp file \"" + fedit_file + "\"");
        if (oSession.oResponse.headers.ToString().ToLower().IndexOf("content-encoding:") >= 0)
        {
            // if encoded, decode it
            File.WriteAllBytes(fedit_file, oSession.responseBodyBytes);
        }
        else
        {
            // else load bytes
            File.WriteAllBytes(fedit_file, oSession.responseBodyBytes);
        }
        FiddlerApplication.Log.LogString(tmp_filename);
        // add AotuResponse rule
        if (tmp_rules.ContainsKey(oSession.fullUrl))
        {
            FiddlerApplication.oAutoResponder.RemoveRule((Fiddler.ResponderRule)tmp_rules[oSession.fullUrl]);
        }
        else
        {
            tmp_rules.Add(oSession.fullUrl, "");
        }
        tmp_rules[oSession.fullUrl] = (Fiddler.ResponderRule)FiddlerApplication.oAutoResponder.AddRule((ruleStr==""||ruleStr==null)?"EXACT:" + oSession.fullUrl:ruleStr, fedit_file, true);
        if(!FiddlerApplication.oAutoResponder.IsEnabled)
            MessageBox.Show("Notice! AutoResponder is not enabled! Please enable this.");

        FiddlerApplication.Log.LogString("Open file \"" + fedit_file + "\"");
        // edit file with default editor
        if (editor_setting.ContainsKey(tmp_filetype))
        {
            System.Diagnostics.Process.Start(editor_setting[tmp_filetype].ToString(), "\"" + fedit_file + "\"");
        }
        else
        {
            System.Diagnostics.Process.Start(editor_setting["default"].ToString(), "\"" + fedit_file + "\"");
        }
        FiddlerApplication.Log.LogString(fedit_file);
    }