Пример #1
0
        // Public Methods 

        public static HttpRequest Parse(string txt)
        {
            var r = new HttpRequest();

            var ln = 0;

            void Pl(string line)
            {
                if (ln++ == 0)
                {
                    r.ParseFirstLine(line);
                }
                else
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        return;
                    }
                    var i1 = line.IndexOf(":");
                    if (i1 < 0)
                    {
                        throw new NotSupportedException();
                    }
                    r.Head[line.Substring(0, i1)] = line.Substring(i1 + 1).TrimStart();
                }
            }

            while (!string.IsNullOrEmpty(txt))
            {
                var idx = txt.IndexOf("\r\n", StringComparison.Ordinal);
                if (idx < 0)
                {
                    Pl(txt);
                    break;
                }
                Pl(txt.Substring(0, idx));
                txt = txt.Substring(idx + 2);
            }
            r.Update();
            return(r);
        }
Пример #2
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);
        }
Пример #3
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;
        }