示例#1
0
        void AbsorbResponseString(string ResponseString)
        {
            this.headers = new ResponseHeaderParameters(this);
            HTTPMessage Msg = new HTTPMessage(ResponseString);

            string[] FirstHeaderParts = Msg.FirstHeader.Split(new char[] { ' ' }, 3);
            if (FirstHeaderParts.Length < 3)
            {
                throw new Exception("Invalid Response Header");
            }
            this.httpVersion = FirstHeaderParts[0];
            if (!(this.HTTPVersion.Equals("HTTP/1.1") || this.HTTPVersion.Equals("HTTP/1.0")))
            {
                throw new Exception("Invalid Response Header");
            }
            try
            {
                this.code = Convert.ToInt32(FirstHeaderParts[1]);
            }
            catch
            {
                throw new Exception("Invalid Response Header");
            }
            this.status  = FirstHeaderParts[2];
            this.headers = new ResponseHeaderParameters(this, Msg.Headers);
            this.SetBody(Msg.BodyString);
        }
示例#2
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);
        }
示例#3
0
 public byte[] GetFullRequestAsByteArray()
 {
     byte[] HeaderArray = Encoding.GetEncoding("ISO-8859-1").GetBytes(this.GetHeadersAsString());
     if (this.bodyArray == null)
     {
         this.bodyArray = new byte[0];
     }
     return(HTTPMessage.GetFullMessageAsByteArray(HeaderArray, this.bodyArray));
 }
示例#4
0
 public byte[] GetFullResponseAsByteArray()
 {
     byte[] HeaderArray = Encoding.GetEncoding("ISO-8859-1").GetBytes(this.GetHeadersAsString());
     return(HTTPMessage.GetFullMessageAsByteArray(HeaderArray, this.BodyArray));
 }
示例#5
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);
        }
示例#6
0
 void AbsorbResponseString(string ResponseString)
 {
     this.headers = new ResponseHeaderParameters(this);
     HTTPMessage Msg = new HTTPMessage(ResponseString);
     string[] FirstHeaderParts = Msg.FirstHeader.Split(new char[] { ' ' }, 3);
     if (FirstHeaderParts.Length < 3)
     {
         throw new Exception("Invalid Response Header");
     }
     this.httpVersion = FirstHeaderParts[0];
     if (!(this.HTTPVersion.Equals("HTTP/1.1") || this.HTTPVersion.Equals("HTTP/1.0")))
     {
         throw new Exception("Invalid Response Header");
     }
     try
     {
         this.code = Convert.ToInt32(FirstHeaderParts[1]);
     }
     catch
     {
         throw new Exception("Invalid Response Header");
     }
     this.status = FirstHeaderParts[2];
     this.headers = new ResponseHeaderParameters(this, Msg.Headers);
     this.SetBody(Msg.BodyString);
 }