Пример #1
0
 void InitiateParameters()
 {
     this.query   = new QueryParameters(this);
     this.body    = new BodyParameters(this);
     this.cookie  = new CookieParameters(this);
     this.headers = new RequestHeaderParameters(this);
 }
Пример #2
0
 void SetParametersFromHeaders(RequestHeaderParameters Headers)
 {
     if (this.headers.Has("Cookie"))
     {
         this.SetCookie(this.headers.Get("Cookie"));
     }
 }
Пример #3
0
        //private non-static methods
        void AbsorbRequestString(string RequestString, bool SSL, bool OverrideSSLParameter)
        {
            HTTPMessage Msg = new HTTPMessage(RequestString);

            this.headers = new RequestHeaderParameters(this, Msg.Headers);
            this.SetParametersFromHeaders(this.headers);
            this.SSL = SSL;
            string[] FirstHeaderParts = new string[3];
            string[] FirstSplit       = Msg.FirstHeader.Split(new string[] { " " }, 2, StringSplitOptions.RemoveEmptyEntries);
            if (FirstSplit.Length != 2)
            {
                throw new Exception("Invalid Request URL");
            }
            FirstHeaderParts[0] = FirstSplit[0];
            int LastSpace = FirstSplit[1].LastIndexOf(" ");

            if (LastSpace < 1 || LastSpace > (FirstSplit[1].Length - 8))
            {
                throw new Exception("Invalid Request URL");
            }
            FirstHeaderParts[1] = FirstSplit[1].Substring(0, LastSpace).Replace(" ", "%20");
            FirstHeaderParts[2] = FirstSplit[1].Substring(LastSpace + 1);
            this.HTTPVersion    = FirstHeaderParts[2];
            if (this.HTTPVersion.Equals("HTTP/1.1"))
            {
                if (!this.Headers.Has("Host"))
                {
                    throw new Exception("Hostname information missing");
                }
            }
            else if (!this.HttpVersion.Equals("HTTP/1.0"))
            {
                throw new Exception("Invalid HTTP version");
            }
            this.Method = FirstHeaderParts[0];
            string URLPart = FirstHeaderParts[1];

            if (URLPart.StartsWith("/"))
            {
                this.URL = URLPart;
                this.AbsorbFullURL(this.FullURL);
            }
            else if (URLPart.StartsWith("https://") || URLPart.StartsWith("http://"))
            {
                this.AbsorbFullURL(URLPart);
                if (!OverrideSSLParameter)
                {
                    this.SSL = SSL;
                }
            }
            else
            {
                throw new Exception("Invalid Request URL");
            }

            //process body
            this.SetBody(Msg.BodyString);
        }
Пример #4
0
 void SetParametersFromHeaders(RequestHeaderParameters Headers)
 {
     if (this.headers.Has("Cookie"))
     {
         this.SetCookie(this.headers.Get("Cookie"));
     }
 }
Пример #5
0
 void InitiateParameters()
 {
     this.query = new QueryParameters(this);
     this.body = new BodyParameters(this);
     this.cookie = new CookieParameters(this);
     this.headers = new RequestHeaderParameters(this);
 }
Пример #6
0
        //private non-static methods
        void AbsorbRequestString(string RequestString, bool SSL, bool OverrideSSLParameter)
        {
            HTTPMessage Msg = new HTTPMessage(RequestString);
            this.headers = new RequestHeaderParameters(this,Msg.Headers);
            this.SetParametersFromHeaders(this.headers);
            this.SSL = SSL;
            string[] FirstHeaderParts = new string[3];
            string[] FirstSplit = Msg.FirstHeader.Split(new string[]{" "}, 2, StringSplitOptions.RemoveEmptyEntries);
            if (FirstSplit.Length != 2)
            {
                throw new Exception("Invalid Request URL");
            }
            FirstHeaderParts[0] = FirstSplit[0];
            int LastSpace = FirstSplit[1].LastIndexOf(" ");
            if (LastSpace < 1 || LastSpace > (FirstSplit[1].Length - 8))
            {
                throw new Exception("Invalid Request URL");
            }
            FirstHeaderParts[1] = FirstSplit[1].Substring(0, LastSpace).Replace(" ", "%20");
            FirstHeaderParts[2] = FirstSplit[1].Substring(LastSpace+1);
            this.HTTPVersion = FirstHeaderParts[2];
            if (this.HTTPVersion.Equals("HTTP/1.1"))
            {
                if (!this.Headers.Has("Host"))
                {
                    throw new Exception("Hostname information missing");
                }
            }
            else if (!this.HttpVersion.Equals("HTTP/1.0"))
            {
                throw new Exception("Invalid HTTP version");
            }
            this.Method = FirstHeaderParts[0];
            string URLPart = FirstHeaderParts[1];
            if (URLPart.StartsWith("/"))
            {
                this.URL = URLPart;
                this.AbsorbFullURL(this.FullURL);
            }
            else if (URLPart.StartsWith("https://") || URLPart.StartsWith("http://"))
            {
                this.AbsorbFullURL(URLPart);
                if (!OverrideSSLParameter)
                {
                    this.SSL = SSL;
                }
            }
            else
            {
                throw new Exception("Invalid Request URL");
            }

            //process body
            this.SetBody(Msg.BodyString);
        }
Пример #7
0
        public static List <string> GetHeaderVariations(string Trigg, HeaderParameters Headers, string HeaderString)
        {
            List <string> FinalMatches = new List <string>();

            if (Trigg.Contains(":"))
            {
                string[] Parts        = Trigg.Split(new char[] { ':' }, 2);
                string   TrimmedName  = Parts[0].Trim();
                string   TrimmedValue = Parts[1].Trim();
                if (TrimmedName.Length > 0)
                {
                    List <string[]> Matches = new List <string[]>();
                    foreach (string Name in Headers.GetNames())
                    {
                        if (Name.Trim().Equals(TrimmedName, StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (string Value in Headers.GetAll(Name))
                            {
                                if (Value.Trim().Equals(TrimmedValue))
                                {
                                    Matches.Add(new string[] { Name, Value });
                                }
                            }
                        }
                    }

                    List <string> Lines = Tools.SplitLines(HeaderString);
                    foreach (string Line in Lines)
                    {
                        foreach (string[] Match in Matches)
                        {
                            string EncodedName  = "";
                            string EncodedValue = "";

                            if (Line.StartsWith(Match[0]))
                            {
                                EncodedName = Match[0];
                            }
                            else if (Line.StartsWith(RequestHeaderParameters.Encode(Match[0])))
                            {
                                EncodedName = RequestHeaderParameters.Encode(Match[0]);
                            }
                            else if (Line.StartsWith(ResponseHeaderParameters.Encode(Match[0])))
                            {
                                EncodedName = ResponseHeaderParameters.Encode(Match[0]);
                            }

                            if (Line.EndsWith(Match[1]))
                            {
                                EncodedValue = Match[1];
                            }
                            else if (Line.EndsWith(RequestHeaderParameters.Encode(Match[1])))
                            {
                                EncodedValue = RequestHeaderParameters.Encode(Match[1]);
                            }
                            else if (Line.EndsWith(ResponseHeaderParameters.Encode(Match[1])))
                            {
                                EncodedValue = ResponseHeaderParameters.Encode(Match[1]);
                            }

                            if (EncodedValue.Length > 0)//If EncodedValue is empty then .Replace(EncodedValue, "") throws an exception, as empty value cannot be replaced
                            {
                                if (Line.Substring(EncodedName.Length).Replace(EncodedValue, "").Trim().Equals(":"))
                                {
                                    FinalMatches.Add(Line);
                                }
                            }
                            else
                            {
                                if (Line.Substring(EncodedName.Length).Trim().Equals(":"))
                                {
                                    FinalMatches.Add(Line);
                                }
                            }
                        }
                    }
                }
            }
            return(FinalMatches);
        }