Beispiel #1
0
        public void SetClientDelCookies(string yourCookieString)
        {
            string tempAttibute = "Max-Age=1;Path=/";

            if (!string.IsNullOrEmpty(yourCookieString))
            {
                SetVaule f = new SetVaule("Set Attibute", "you can add attibute for the set-cookie head ,like Domain=www.yourhost.com", tempAttibute, new Func <string, bool>((string checkValue) => { return(checkValue.Contains("Max-Age")); }));
                f.OnSetValue += new EventHandler <SetVaule.SetVauleEventArgs>((obj, tag) => { tempAttibute = tag.SetValue; });
                f.ShowDialog();
            }
            SetClientCookies(yourCookieString, new Func <KeyValuePair <string, string>, bool>((kvCookie) =>
            {
                responseAddHeads.ListDataView.Items.Add(string.Format("Set-Cookie: {0}=delete by FreeHttp; {1}", kvCookie.Key, tempAttibute));
                return(true);
            }));
        }
Beispiel #2
0
 private void pb_responseLatency_Click(object sender, EventArgs e)
 {
     if (IsSetResponseLatencyEable)
     {
         SetVaule f = new SetVaule("Set Latency", "Enter the exact number of milliseconds by which to delay the response", sender == pb_responseLatency ? "0" : lbl_ResponseLatency.GetLatency().ToString(), new Func <string, bool>((string checkValue) => { int tempValue; if (checkValue == "")
                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                  return(true);
                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                              return(int.TryParse(checkValue, out tempValue) && tempValue >= 0); }));
         f.OnSetValue += f_OnSetValue;
         f.ShowDialog();
     }
     else
     {
         MessageBox.Show("Can not set latency  in reqest modific mode\r\njust change to response modific mode", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
     }
 }
Beispiel #3
0
 void myEnableSwitch_IsEnableHttpsService_OnChangeEnable(object sender, MyEnableSwitch.ChangeEnableEventArgs e)
 {
     if (e.IsEnable)
     {
         if (!MyGlobalHelper.IsAdministrator())
         {
             MessageBox.Show("Enable http sevice need administrator rights \r\nPlease use administrator privileges to open the application", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             myEnableSwitch_IsEnableHttpsService.IsEnable = false;
             return;
         }
         bool isAffirm     = false;
         int  listenerPort = 443;
         if (FreeHttp.WebService.HttpServer.MySocketHelper.IsPortInTcpListening(listenerPort))
         {
             listenerPort = 9990;
             while (FreeHttp.WebService.HttpServer.MySocketHelper.IsPortInTcpListening(listenerPort))
             {
                 listenerPort++;
                 if (listenerPort == 65537)
                 {
                     MessageBox.Show("can not find leisure port from 9990 to 65536", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                     myEnableSwitch_IsEnableHttpsService.IsEnable = false;
                     return;
                 }
             }
         }
         string   listenerPrefixesStr = string.Format(@"https://*:{0}/", listenerPort);
         SetVaule f = new SetVaule("Set listener prefixes", "you can set listener prefixes for your http service,like https://*:443/", listenerPrefixesStr, new Func <string, string>((string checkValue) => { return(checkValue.StartsWith("http") && checkValue.EndsWith("/")?null:""); }));
         f.OnSetValue += new EventHandler <SetVaule.SetVauleEventArgs>((obj, tag) => { listenerPrefixesStr = tag.SetValue; isAffirm = true; });
         f.ShowDialog();
         if (!isAffirm)
         {
             myEnableSwitch_IsEnableHttpsService.IsEnable = false;
             return;
         }
         int portIndex = listenerPrefixesStr.LastIndexOf(":");
         if (!(portIndex > 0 && listenerPrefixesStr.EndsWith("/") && int.TryParse(listenerPrefixesStr.Substring(portIndex + 1, listenerPrefixesStr.Length - portIndex - 2), out listenerPort)))
         {
             MessageBox.Show("your listener prefixes is illegality", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             myEnableSwitch_IsEnableHttpsService.IsEnable = false;
             return;
         }
         if (Fiddler.CertMaker.GetRootCertificate() == null)
         {
             MessageBox.Show("can not get Fiddler RootCertificate", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             myEnableSwitch_IsEnableHttpsService.IsEnable = false;
             return;
         }
         else
         {
             if (FreeHttp.WebService.HttpServer.MySocketHelper.IsPortInTcpListening(listenerPort))
             {
                 MessageBox.Show(string.Format("this port {0} is in listening with other process", listenerPort), "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                 myEnableSwitch_IsEnableHttpsService.IsEnable = false;
                 return;
             }
             try
             {
                 FreeHttp.WebService.HttpServer.CertificatesHelper.AddCertificateToX509Store(Fiddler.CertMaker.GetRootCertificate());
                 FreeHttp.WebService.HttpServer.CertificatesHelper.BindingCertificate(Fiddler.CertMaker.GetRootCertificate(), listenerPort);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(string.Format("fail to BindingCertificate with {0}", ex.Message), "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                 myEnableSwitch_IsEnableHttpsService.IsEnable = false;
                 return;
             }
         }
         try
         {
             MyGlobalHelper.myHttpListener.Start(listenerPrefixesStr);
             MyGlobalHelper.PutGlobalMessage(this, new MyGlobalHelper.GlobalMessageEventArgs(false, string.Format("add listening for [{0}]", listenerPrefixesStr)));
         }
         catch (Exception ex)
         {
             MessageBox.Show(string.Format("fail to Start HttpListener with {0}", ex.Message), "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             MyGlobalHelper.myHttpListener.Stop();
             myEnableSwitch_IsEnableHttpsService.IsEnable = false;
             return;
         }
     }
     else
     {
         MyGlobalHelper.myHttpListener.Stop();
     }
 }