상속: Header
예제 #1
0
파일: Slow.cs 프로젝트: hultqvist/HitProxy
        public override Response Status(NameValueCollection httpGet, Request request)
        {
            if (httpGet ["action"] != null) {
                int.TryParse (httpGet ["speedlimit"], out speedLimit);
                int.TryParse (httpGet ["delay"], out delay);
                SaveSettings ();
            }

            Html html = Html.Format (@"
                <p>Slows down the receiving speed to simulate slow websites, triggered by <strong>slow</strong> flag.</p>
                <form action=""?"" method=""get"">
                    <table>
                    <tr>
                        <th>Speed limit</th><td><input type=""text"" name=""speedlimit"" value=""{0}"" /> bytes/second</td>
                    </tr>
                    <tr>
                        <th>Delay</th><td><input type=""text"" name=""delay"" value=""{1}"" /> milliseconds</td>
                    </tr>
                    <tr>
                        <th></th><td><input type=""submit"" name=""action"" value=""Save"" /></td>
                    </tr>
                </form>", this.speedLimit, this.delay);

            return WebUI.ResponseTemplate (ToString (), html);
        }
예제 #2
0
 public override bool Apply(Request request)
 {
     if (request.Method == "CONNECT") {
         request.InterceptSSL = true;
         return true;
     }
     return false;
 }
예제 #3
0
        public override bool Apply(Request request)
        {
            TimeSpan now = DateTime.Now.TimeOfDay;
            if (now.Hours < 12 || now.Hours > 13)
                return false;

            request.Flags.Set ("break");
            return true;
        }
예제 #4
0
        /// <summary>
        /// Catch .<tld> urls and pass them through a proxy
        /// </summary>
        public override bool Apply(Request request)
        {
            if (!request.Uri.Host.EndsWith ("." + tld))
                return false;

            request.Proxy = proxyUri;
            request.ProxyDns = proxyDns;
            return true;
        }
예제 #5
0
파일: Saver.cs 프로젝트: hultqvist/HitProxy
 public override Response Status(NameValueCollection httpGet, Request request)
 {
     Html html = Html.Format (@"<p>Saves request data with flag <strong>save</strong> onto disk.</p><ul>");
     lock (savings) {
         foreach (FileSaver fo in savings) {
             html += Html.Format (@"<li>{0}</li>", fo);
         }
     }
     return WebUI.ResponseTemplate (ToString (), html + Html.Format ("</ul>"));
 }
예제 #6
0
        public override bool Apply(Request request)
        {
            if (request.Flags ["pass"] == true)
                return false;

            request.ReplaceHeader ("Accept", "*/*");
            request.ReplaceHeader ("Accept-Charset", "utf-8");
            request.ReplaceHeader ("Accept-Encoding", "gzip, deflate");
            return true;
        }
예제 #7
0
파일: Block.cs 프로젝트: hultqvist/HitProxy
        public override bool Apply(Request request)
        {
            if (request.Flags["block"] == false)
                return false;

            Html status = new Html ();
            Html hr = Html.Format ("<hr/>");
            foreach (Html h in request.GetTriggerHtml ())
                status += h + hr;

            request.Response = new BlockedResponse ("Blocked", status);
            return true;
        }
예제 #8
0
        public override bool Apply(Request request)
        {
            Filter[] list = ToArray ();
            if (list.Length == 0)
                return false;

            if (list[0].Apply (request) == false)
                return false;

            foreach (Filter f in ToArray ())
                f.Apply (request);

            return true;
        }
예제 #9
0
파일: Slow.cs 프로젝트: hultqvist/HitProxy
        public override bool Apply(Request request)
        {
            if (request.Response == null)
                return false;
            if ((request.Flags ["slow"] || request.Response.Flags ["slow"]) == false)
                return false;

            //Added delay
            Thread.Sleep (delay);

            //Intercept data connection
            request.Response.Stream = new SlowReader (request.Response.Stream, this);

            return true;
        }
예제 #10
0
        public override bool Apply(Request request)
        {
            lock (this) {
                last = request.FirstLine + "<br/>";
                foreach (string header in request)
                    last += header + "<br/>";

                if (request.Response != null) {
                    last += "<br/>" + request.Response.FirstLine + "<br/>";
                    foreach (string header in request.Response)
                        last += header + "<br/>";
                }
            }
            return false;
        }
예제 #11
0
        public override bool Apply(Request request)
        {
            int headers = request.Count;

            string connection = request.GetHeader ("Proxy-Connection");
            request.RemoveHeader ("Proxy-Connection");
            if (connection == null)
                request.ReplaceHeader ("Connection", "close");
            else
                request.ReplaceHeader ("Connection", connection);

            if (headers != request.Count)
                return true;
            else
                return false;
        }
예제 #12
0
파일: Saver.cs 프로젝트: hultqvist/HitProxy
        public override bool Apply(Request request)
        {
            if (request.Response == null)
                return false;
            if ((request.Flags ["save"] || request.Response.Flags ["save"]) == false)
                return false;

            //Intercept data connection
            FileSaver save = new FileSaver (request, this, request.Response.Stream);
            lock (savings) {
                savings.Add (save);
            }
            request.Response.Stream = save;

            return true;
        }
예제 #13
0
파일: Saver.cs 프로젝트: hultqvist/HitProxy
            public FileSaver(Request request, Saver saver, Stream input)
            {
                try {
                    path = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "Downloads");
                    Directory.CreateDirectory (path);
                    DateTime now = DateTime.Now;
                    path = Path.Combine (path, now.ToShortDateString () + " " + now.ToLongTimeString () + " ");
                    path += request.Uri.Host + " " + new Random ().Next (100) + " " + Path.GetFileName (request.Uri.AbsolutePath);

                    file = new FileStream (path, FileMode.Create);
                    this.input = input;
                } catch (Exception) {
                    file.NullSafeDispose ();
                    file = null;
                }

                this.saver = saver;
            }
예제 #14
0
        public override bool Apply(Request request)
        {
            if (request.Response != null) {
                request.Response.Add ("X-PP-User-Agent: " + request.GetHeader ("User-Agent"));
                return false;
            }

            try {
                listLock.EnterReadLock ();

                if (staticAgent.ContainsKey (request.Uri.Host)) {
                    UserAgentRule r = staticAgent[request.Uri.Host];

                    if (r.UserAgent == "") {
                        request.RemoveHeader ("User-Agent");
                    } else if (r.UserAgent.ToLowerInvariant () == "random") {
                        request.ReplaceHeader ("User-Agent", RandomUserAgent ());
                    } else if (r.UserAgent.ToLowerInvariant () != "pass") {
                        request.ReplaceHeader ("User-Agent", r.UserAgent);
                    }

                    if (r.Lang == "") {
                        request.RemoveHeader ("Accept-Language");
                    } else if (r.Lang.ToLowerInvariant () == "random") {
                        request.ReplaceHeader ("Accept-Language", GetRandom (lang));
                    } else if (r.Lang.ToLowerInvariant () != "pass") {
                        request.ReplaceHeader ("Accept-Language", r.Lang);
                    }

                } else {
                    //Default
                    request.ReplaceHeader ("User-Agent", RandomUserAgent ());
                    request.RemoveHeader ("Accept-Language");
                }
            } finally {
                listLock.TryExitReadLock ();
            }
            return true;
        }
예제 #15
0
 public override bool Apply(Request request)
 {
     Active = false;
     throw new NotImplementedException ();
 }
예제 #16
0
        public override Response Status(NameValueCollection httpGet, Request request)
        {
            Html html = Html.Format ("<p>Replaces the User-Agent and Accept-Language headers with random ones</p>");
            html += Html.Format ("<p><strong>Your: </strong> {0}</p>", request.GetHeader ("User-Agent"));
            html += Html.Format ("<p><strong>Random: </strong> {0}</p>", RandomUserAgent ());

            if (httpGet["delete"] != null) {
                try {
                    listLock.EnterWriteLock ();
                    staticAgent.Remove (httpGet["delete"]);
                } finally {
                    listLock.TryExitWriteLock ();
                }

                saveSettings ();
            }

            if (httpGet["action"] != null) {
                UserAgentRule r = new UserAgentRule ();
                r.Domain = httpGet["domain"];
                r.Lang = httpGet["lang"];
                if (httpGet["action"] == "Permanent")
                    r.Permanent = true;
                r.UserAgent = httpGet["agent"];
                if (r.UserAgent.ToLowerInvariant () == "random") {
                    r.UserAgent = RandomUserAgent ();
                    r.Random = true;
                }

                try {
                    listLock.EnterWriteLock ();
                    staticAgent.Add (r.Domain, r);
                } finally {
                    listLock.TryExitWriteLock ();
                }

                if (r.Permanent)
                    saveSettings ();
            }

            html += Html.Format (@"<form action=""?"" method=""get"">
                                <p><label for=""domain"">Domain</label>: <input type=""text"" name=""domain"" value="""" /></p>
                                <p><label for=""lang"">Language</label>: <input type=""text"" name=""lang"" value="""" /></p>
                                <p><label for=""agent"">User-Agent</label>: <input type=""text"" name=""agent"" value="""" />
                                    ""random"" = change every session.
                                    ""pass"" = pass through unmodified</p>
                                <input type=""submit"" name=""action"" value=""Permanent"" />
                                <input type=""submit"" name=""action"" value=""Temporary"" />
                            </form>");
            try {
                listLock.EnterReadLock ();

                foreach (UserAgentRule rule in staticAgent.Values) {
                    html += Html.Format ("<p>{0} <a href=\"?delete={1}\">delete</a></p>", rule, rule.Domain);
                }
            } finally {
                listLock.ExitReadLock ();
            }

            return WebUI.ResponseTemplate (ToString (), html);
        }
예제 #17
0
 public virtual Response Status(NameValueCollection httpGet, Request request)
 {
     return WebUI.ResponseTemplate (ToString (), Status ());
 }
예제 #18
0
 public override bool Apply(Request request)
 {
     throw new System.NotImplementedException ();
 }
예제 #19
0
 /// <summary>
 /// Can be used to filter both requests and responses
 /// For response filtering the request.Response is set
 /// </summary>
 /// <returns>True if some filter was applied</returns>
 public abstract bool Apply(Request request);