public void chompBalancedMatchesAsMuchAsPossible()
        {
            TokenQueue tq = new TokenQueue("unbalanced(something(or another");

            tq.ConsumeTo("(");
            string match = tq.ChompBalanced('(', ')');

            Assert.AreEqual("something(or another", match);
        }
        public void chompBalanced()
        {
            TokenQueue tq        = new TokenQueue(":contains(one (two) three) four");
            string     pre       = tq.ConsumeTo("(");
            string     guts      = tq.ChompBalanced('(', ')');
            string     remainder = tq.Remainder();

            Assert.AreEqual(":contains", pre);
            Assert.AreEqual("one (two) three", guts);
            Assert.AreEqual(" four", remainder);
        }
Beispiel #3
0
        public void ProcessResponseHeaders(WebHeaderCollection resHeaders)
        {
            foreach (string name in resHeaders.AllKeys)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;                     // http/1.1 line
                }

                var value = resHeaders[name];                 //.Split(';');

                if (name.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase))
                {
                    var values = resHeaders["Set-Cookie"].Split(';', ',');
                    foreach (string v in values)
                    {
                        if (string.IsNullOrWhiteSpace(v))
                        {
                            continue;
                        }

                        var cd         = new TokenQueue(v);
                        var cookieName = cd.ChompTo("=").Trim();
                        var cookieVal  = cd.ConsumeTo(";").Trim();

                        if (cookieVal == null)
                        {
                            cookieVal = string.Empty;
                        }

                        // ignores path, date, domain, secure et al. req'd?
                        if (StringUtil.In(cookieName.ToLowerInvariant(), "domain", "path", "expires", "max-age", "secure", "httponly"))
                        {
                            // This is added for NSoup, since we do headers a bit differently around here.
                            continue;
                        }

                        // name not blank, value not null
                        if (!string.IsNullOrEmpty(cookieName))
                        {
                            Cookie(cookieName, cookieVal);
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        Header(name, /*values[0]*/ value);
                    }
                }
            }
        }
Beispiel #4
0
        public void ProcessResponseHeaders(WebHeaderCollection resHeaders)
        {
            foreach (string name in resHeaders.Keys)
            {
                if (name == null)
                {
                    continue; // http/1.1 line
                }

                string value = resHeaders[name]; //.Split(';');

                if (name.Equals("Set-Cookie", StringComparison.InvariantCultureIgnoreCase))
                {
                    string[] values = resHeaders["Set-Cookie"].Split(';', ',');
                    foreach (string v in values)
                    {
                        if (v == null)
                        {
                            continue;
                        }

                        TokenQueue cd         = new TokenQueue(v);
                        string     cookieName = cd.ChompTo("=").Trim();
                        string     cookieVal  = cd.ConsumeTo(";").Trim();

                        if (cookieVal == null)
                        {
                            cookieVal = string.Empty;
                        }

                        // ignores path, date, domain, secure et al. req'd?
                        if (StringUtil.In(cookieName.ToLowerInvariant(), "domain", "path", "expires", "max-age", "secure", "httponly"))
                        {
                            // This is added for Texxtoor.BaseLibrary.Core.HtmlAgility.ToXml, since we do headers a bit differently around here.
                            continue;
                        }

                        // name not blank, value not null
                        if (!string.IsNullOrEmpty(cookieName))
                        {
                            Cookie(cookieName, cookieVal);
                        }
                    }
                }
                else
                { // only take the first instance of each header
                    if (/*values.Length > 0*/ !string.IsNullOrEmpty(value))
                    {
                        Header(name, /*values[0]*/ value);
                    }
                }
            }
        }