示例#1
0
        protected bool Operators()
        {
            var bs = (T)Activator.CreateInstance(typeof(T), "HTTP/1.1 404 Not found\r\nSuperHeader::master value\r\nSuperHeader!master value\r\nSuperHeader:-:master value\r\nHeader1: data1\r\nCookie: theme=light; sessionToken=abc123\r\nHeaderMultiple: x 1\r\nHeaderMultiple: x 2\r\nHeaderMultiple: x 3\r\nHeader2: data2\r\nHeader3: data3\r\nHeader4: data4\r\n\r\n      Hello! This is the body!");

            ParserResult root = bs
                                | "HTTP/[version: ]"
                                | "[i/code: ]"
                                | "[message:\r\n]"
                                | "[<headers:\r\n\r\n>]{[name:::!\r\n][|value|:\r\n|$]||[name:\\!!\r\n][|value|:\r\n|$]||[name::!\r\n][|value|:\r\n|$]}[</>]"
                                | "[$s/body$]";

            if (IsVerbose)
            {
                Console.WriteLine(":: Operators");

                Console.WriteLine(" :!*********************: headers.<$name=HeaderMultiple$>.value");
                foreach (var e in root.GetAll <string>("headers.<$name=HeaderMultiple$>.value"))
                {
                    Console.WriteLine(" :!: " + e);
                }
                Console.WriteLine(" :!*********************: ");

                Console.WriteLine("Version :");
                Console.WriteLine(root["version"]);
                Console.WriteLine("Code :");
                Console.WriteLine(root["code"]);
                Console.WriteLine("Message :");
                Console.WriteLine(root["message"]);

                Console.WriteLine("Headers :");

                Console.WriteLine("Cookies : " + root.GetString("headers.<|name=cookie|>.value") + "|");

                var cookies = ByteSequencer.Parse(
                    "[<cookies:$>][|name|:=][value:;|$][</>]",
                    root.GetString("headers.<|name=cookie|>.value")
                    ).Close();

                foreach (var e in cookies.GetList("cookies"))
                {
                    Console.WriteLine(e["name"] + " //=// " + e["value"]);
                }

                Console.WriteLine("Body :");
                Console.WriteLine(root["body"]);
            }

            return(true);
        }
示例#2
0
        protected bool ParsedTest()
        {
            ParserResult root = ISequencer <T> .Parse(
                "[version: ][i/code: ][message:\r\n][<headers:\r\n\r\n>][name::][|value|:\r\n|$][</>][$|body|$]",
                "HTTP/1.1 404 Not found\r\nHeader1: data1\r\nCookie: theme=light; sessionToken=abc123\r\nHeaderMultiple: x 1\r\nHeaderMultiple: x 2\r\nHeaderMultiple: x 3\r\nHeader2: data2\r\nHeader3: data3\r\nHeader4: data4\r\n\r\n      Hello! This is the body!".GetBytes()
                ).Close();

            if (IsVerbose)
            {
                Console.WriteLine(":: ParsedTest");

                Console.WriteLine(" :!*********************: headers.<$name=HeaderMultiple$>.value");
                foreach (var e in root.GetAll <string>("headers.<$name=HeaderMultiple$>.value"))
                {
                    Console.WriteLine(" :!: " + e);
                }
                Console.WriteLine(" :!*********************: ");

                Console.WriteLine("Version :");
                Console.WriteLine(root["version"]);
                Console.WriteLine("Code :");
                Console.WriteLine(root["code"]);
                Console.WriteLine("Message :");
                Console.WriteLine(root["message"]);

                Console.WriteLine("Headers :");
                foreach (var e in root.GetList("headers"))
                {
                    Console.WriteLine(e["name"] + " = " + e["value"] + "|");
                }

                Console.WriteLine("Cookies :");

                var cookies = ByteSequencer.Parse(
                    "[<cookies:$>][|name|:=][value:;|$][</>]",
                    root.GetString("headers.<|name=cookie|>.value")
                    ).Close();

                foreach (var e in cookies.GetList("cookies"))
                {
                    Console.WriteLine(e["name"] + " //=// " + e["value"]);
                }

                Console.WriteLine("Body :");
                Console.WriteLine(root["body"]);
            }

            if (!root["version"].Equals("HTTP/1.1"))
            {
                return(false);
            }

            if (!root["code"].Equals(404))
            {
                return(false);
            }

            if (!root["message"].Equals("Not found"))
            {
                return(false);
            }

            if (!root["headers.<0>.name"].Equals("Header1"))
            {
                return(false);
            }
            if (!root["headers.<0>.value"].Equals("data1"))
            {
                return(false);
            }

            if (!root["headers.<5>.name"].Equals("Header2"))
            {
                return(false);
            }
            if (!root["headers.<5>.value"].Equals("data2"))
            {
                return(false);
            }

            if (!root["headers.<6>.name"].Equals("Header3"))
            {
                return(false);
            }
            if (!root["headers.<6>.value"].Equals("data3"))
            {
                return(false);
            }

            if (!root["headers.<7>.name"].Equals("Header4"))
            {
                return(false);
            }
            if (!root["headers.<7>.value"].Equals("data4"))
            {
                return(false);
            }

            if (!root["body"].Equals("Hello! This is the body!"))
            {
                return(false);
            }

            return(true);
        }