Ejemplo n.º 1
0
        // Public Methods 

        public static HttpRequest Parse(string txt)
        {

            HttpRequest r = new HttpRequest();

            int ln = 0;
            Action<string> pl = (string line) =>
            {
                if (ln++ == 0)
                    r.ParseFirstLine(line);
                else
                {
                    if (string.IsNullOrEmpty(line))
                        return;
                    int i1 = line.IndexOf(":");
                    if (i1 < 0)
                        throw new NotSupportedException();
                    r._head[line.Substring(0, i1)] = line.Substring(i1 + 1).TrimStart();

                }

            };

            while (!string.IsNullOrEmpty(txt))
            {
                int idx = txt.IndexOf("\r\n");
                if (idx < 0)
                {
                    pl(txt);
                    break;
                }
                pl(txt.Substring(0, idx));
                txt = txt.Substring(idx + 2);

            }
            r.Update();
            return r;
        }