예제 #1
0
        /// <summary>
        /// Construct a Request object that contains the information received from the client
        /// </summary>
        /// <param name="stream">The stream associated to the TCPClient</param>
        /// <param name="server">The server that handled the request</param>
        internal Request(Stream stream, Server server)
        {
            this.server = server;
            this.m_ClientIP = "";

            // Receive max 16k from the client
            Byte[] receiveBuffer = new Byte[16384];
            int i = stream.Read(receiveBuffer, 0 , receiveBuffer.Length);

            // Convert the data received to UTF8
            this.sBuffer = Encoding.UTF8.GetString(receiveBuffer);

            this.m_Cookies = new ArrayList();
            this.m_Ranges = new ArrayList();
            this.parameters = new Hashtable();

            Tokenizer toki = new Tokenizer(sBuffer, "\r\n");
            Tokenizer fullRequest = new Tokenizer(toki.nextToken(), " ");
            m_Method = fullRequest.nextToken();
            m_Path = fullRequest.nextToken();
            Tokenizer path = new Tokenizer(m_Path.Substring(1), "?");
            Page = path.nextToken();
            parseParameters(path.nextToken());

            m_HTTPVersion = fullRequest.nextToken();

            while (toki.hasMoreTokens())
            {
                string temp = toki.nextToken();
                if (temp != null)
                {
                    if (temp.IndexOf("Accept:") == 0) m_Accept = substract(temp);
                    else if (temp.IndexOf("Accept-Language:") == 0) m_AcceptLanguage = substract(temp);
                    else if (temp.IndexOf("Accept-Encoding:") == 0) m_AcceptEncoding = substract(temp);
                    else if (temp.IndexOf("User-Agent:") == 0) m_UserAgent = substract(temp);
                    else if (temp.IndexOf("Host:") == 0) m_Host = substract(temp);
                    else if (temp.IndexOf("Connection:") == 0) m_Connection = substract(temp);
                    else if (temp.IndexOf("Authorization:") == 0) m_Authorization = substract(temp);
                    else if (temp.IndexOf("Cookie:") == 0)
                    {
                        string cookiesTemp = substract(temp);
                        Tokenizer cookiesToki = new Tokenizer(cookiesTemp, "; ");
                        while (cookiesToki.hasMoreTokens())
                        {
                            string cookieTemp = cookiesToki.nextToken();
                            Tokenizer inCookie = new Tokenizer(cookieTemp, "=");
                            this.m_Cookies.Add(new Cookie(inCookie.nextToken(), inCookie.nextToken()));
                        }
                    }
                    else if (temp.IndexOf("Range:") == 0)
                    {
                        string rangesTemp = substract(temp);
                        Tokenizer rangeValues = new Tokenizer(rangesTemp, "=");
                        string rangeType = rangeValues.nextToken();
                        Tokenizer differentRanges = new Tokenizer(rangeValues.nextToken(), ",");
                        while (differentRanges.hasMoreTokens())
                        {

                            string range = differentRanges.nextToken();
                            this.m_Ranges.Add(new Range(range));
                        }
                    }
                    else if (temp == "")
                    {
                        if (Method == "POST")
                        {
                            parseParameters(toki.nextToken());
                        }
                    }
                }
            }
        }
예제 #2
0
 void parseParameters(string parameters_tokenized)
 {
     Tokenizer parameters_token = new Tokenizer(parameters_tokenized, "&");
     while (parameters_token.hasMoreTokens())
     {
         Tokenizer tempi = new Tokenizer(parameters_token.nextToken(), "=");
         parameters.Add(tempi.nextToken(), HTMLHelper.decode(tempi.nextToken()));
     }
 }