Esempio n. 1
0
        private static void ParseRequestLine(string line, SimplifiedClientRequest request)
        {
            string[] parts = line.Split();

            request.RequestType = (ClientRequestType)Enum.Parse(typeof(ClientRequestType), parts[0], true);
            request.Url         = parts[1];
            request.HttpVersion = parts[2];
        }
Esempio n. 2
0
        private static void ParseHeaderLine(string line, SimplifiedClientRequest request)
        {
            string[] parts = line.Split(':').Select(x => x.Trim()).ToArray();

            switch (parts[0].ToUpper())
            {
            case "CONTENT-LENGHT":
                request.ContentLength = Int32.Parse(parts[1]);
                break;

            case "CONNECTION":
                request.Connection = ParseRequestConnectionType(parts[1]);
                break;

            case "COOKIE":
                request.Cookies = parts[1].Split(',').Select(x => x.Trim()).ToArray();
                break;
            }
        }
Esempio n. 3
0
        public static SimplifiedClientRequest ParseRequest(string requestString)
        {
            SimplifiedClientRequest request = new SimplifiedClientRequest();

            string[] requestLines = requestString.Split('\n');

            ParseRequestLine(requestLines[0], request);

            int i;

            for (i = 1; i < requestLines.Length; i++)
            {
                if (!String.IsNullOrEmpty(requestLines[i]))
                {
                    ParseHeaderLine(requestLines[i], request);
                }
                else
                {
                    break;
                }
            }

            if (request.ContentLength > 0)
            {
                StringBuilder sb = new StringBuilder();

                for (; i < requestLines.Length; i++)
                {
                    sb.AppendLine(requestLines[i]);
                }

                request.MessageBody = sb.ToString();
            }

            return(request);
        }