Ejemplo n.º 1
0
        private static CookieCollection parseResponse(string value)
        {
            CookieCollection cookieCollection = new CookieCollection();
            Cookie           cookie           = null;

            string[] array = CookieCollection.splitCookieHeaderValue(value);
            for (int i = 0; i < array.Length; i++)
            {
                string text = array[i].Trim();
                if (text.Length != 0)
                {
                    if (text.StartsWith("version", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Version = int.Parse(text.GetValueInternal("=").Trim(new char[]
                            {
                                '"'
                            }));
                        }
                    }
                    else if (text.StartsWith("expires", StringComparison.InvariantCultureIgnoreCase))
                    {
                        StringBuilder stringBuilder = new StringBuilder(text.GetValueInternal("="), 32);
                        if (i < array.Length - 1)
                        {
                            stringBuilder.AppendFormat(", {0}", array[++i].Trim());
                        }
                        DateTime now;
                        if (!DateTime.TryParseExact(stringBuilder.ToString(), new string[]
                        {
                            "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'",
                            "r"
                        }, CultureInfo.CreateSpecificCulture("en-US"), DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out now))
                        {
                            now = DateTime.Now;
                        }
                        if (cookie != null && cookie.Expires == DateTime.MinValue)
                        {
                            cookie.Expires = now.ToLocalTime();
                        }
                    }
                    else if (text.StartsWith("max-age", StringComparison.InvariantCultureIgnoreCase))
                    {
                        int num = int.Parse(text.GetValueInternal("=").Trim(new char[]
                        {
                            '"'
                        }));
                        DateTime expires = DateTime.Now.AddSeconds((double)num);
                        if (cookie != null)
                        {
                            cookie.Expires = expires;
                        }
                    }
                    else if (text.StartsWith("path", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Path = text.GetValueInternal("=");
                        }
                    }
                    else if (text.StartsWith("domain", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Domain = text.GetValueInternal("=");
                        }
                    }
                    else if (text.StartsWith("port", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string port = (!text.Equals("port", StringComparison.InvariantCultureIgnoreCase)) ? text.GetValueInternal("=") : "\"\"";
                        if (cookie != null)
                        {
                            cookie.Port = port;
                        }
                    }
                    else if (text.StartsWith("comment", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Comment = text.GetValueInternal("=").UrlDecode();
                        }
                    }
                    else if (text.StartsWith("commenturl", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.CommentUri = text.GetValueInternal("=").Trim(new char[]
                            {
                                '"'
                            }).ToUri();
                        }
                    }
                    else if (text.StartsWith("discard", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Discard = true;
                        }
                    }
                    else if (text.StartsWith("secure", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Secure = true;
                        }
                    }
                    else if (text.StartsWith("httponly", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.HttpOnly = true;
                        }
                    }
                    else
                    {
                        if (cookie != null)
                        {
                            cookieCollection.Add(cookie);
                        }
                        string value2 = string.Empty;
                        int    num2   = text.IndexOf('=');
                        string name;
                        if (num2 == -1)
                        {
                            name = text;
                        }
                        else if (num2 == text.Length - 1)
                        {
                            name = text.Substring(0, num2).TrimEnd(new char[]
                            {
                                ' '
                            });
                        }
                        else
                        {
                            name = text.Substring(0, num2).TrimEnd(new char[]
                            {
                                ' '
                            });
                            value2 = text.Substring(num2 + 1).TrimStart(new char[]
                            {
                                ' '
                            });
                        }
                        cookie = new Cookie(name, value2);
                    }
                }
            }
            if (cookie != null)
            {
                cookieCollection.Add(cookie);
            }
            return(cookieCollection);
        }
Ejemplo n.º 2
0
        private static CookieCollection parseResponse(string value)
        {
            DateTime         now;
            string           str;
            CookieCollection cookieCollections = new CookieCollection();
            Cookie           localTime         = null;

            string[] strArrays = CookieCollection.splitCookieHeaderValue(value);
            for (int i = 0; i < (int)strArrays.Length; i++)
            {
                string str1 = strArrays[i].Trim();
                if (str1.Length != 0)
                {
                    if (str1.StartsWith("version", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            localTime.Version = int.Parse(str1.GetValue('=', true));
                        }
                    }
                    else if (str1.StartsWith("expires", StringComparison.InvariantCultureIgnoreCase))
                    {
                        StringBuilder stringBuilder = new StringBuilder(str1.GetValue('='), 32);
                        if (i < (int)strArrays.Length - 1)
                        {
                            int num = i + 1;
                            i = num;
                            stringBuilder.AppendFormat(", {0}", strArrays[num].Trim());
                        }
                        if (!DateTime.TryParseExact(stringBuilder.ToString(), new string[] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" }, CultureInfo.CreateSpecificCulture("en-US"), DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out now))
                        {
                            now = DateTime.Now;
                        }
                        if ((localTime == null ? false : localTime.Expires == DateTime.MinValue))
                        {
                            localTime.Expires = now.ToLocalTime();
                        }
                    }
                    else if (str1.StartsWith("max-age", StringComparison.InvariantCultureIgnoreCase))
                    {
                        int      num1     = int.Parse(str1.GetValue('=', true));
                        DateTime dateTime = DateTime.Now.AddSeconds((double)num1);
                        if (localTime != null)
                        {
                            localTime.Expires = dateTime;
                        }
                    }
                    else if (str1.StartsWith("path", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            localTime.Path = str1.GetValue('=');
                        }
                    }
                    else if (str1.StartsWith("domain", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            localTime.Domain = str1.GetValue('=');
                        }
                    }
                    else if (str1.StartsWith("port", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string str2 = (str1.Equals("port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : str1.GetValue('='));
                        if (localTime != null)
                        {
                            localTime.Port = str2;
                        }
                    }
                    else if (str1.StartsWith("comment", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            localTime.Comment = str1.GetValue('=').UrlDecode();
                        }
                    }
                    else if (str1.StartsWith("commenturl", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            localTime.CommentUri = str1.GetValue('=', true).ToUri();
                        }
                    }
                    else if (str1.StartsWith("discard", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            localTime.Discard = true;
                        }
                    }
                    else if (str1.StartsWith("secure", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            localTime.Secure = true;
                        }
                    }
                    else if (!str1.StartsWith("httponly", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (localTime != null)
                        {
                            cookieCollections.Add(localTime);
                        }
                        string empty = string.Empty;
                        int    num2  = str1.IndexOf('=');
                        if (num2 == -1)
                        {
                            str = str1;
                        }
                        else if (num2 != str1.Length - 1)
                        {
                            str   = str1.Substring(0, num2).TrimEnd(new char[] { ' ' });
                            empty = str1.Substring(num2 + 1).TrimStart(new char[] { ' ' });
                        }
                        else
                        {
                            str = str1.Substring(0, num2).TrimEnd(new char[] { ' ' });
                        }
                        localTime = new Cookie(str, empty);
                    }
                    else if (localTime != null)
                    {
                        localTime.HttpOnly = true;
                    }
                }
            }
            if (localTime != null)
            {
                cookieCollections.Add(localTime);
            }
            return(cookieCollections);
        }
Ejemplo n.º 3
0
        private static CookieCollection parseRequest(string value)
        {
            CookieCollection cookieCollection = new CookieCollection();
            Cookie           cookie           = null;
            int num = 0;

            string[] array = CookieCollection.splitCookieHeaderValue(value);
            for (int i = 0; i < array.Length; i++)
            {
                string text = array[i].Trim();
                if (text.Length != 0)
                {
                    if (text.StartsWith("$version", StringComparison.InvariantCultureIgnoreCase))
                    {
                        num = int.Parse(text.GetValueInternal("=").Trim(new char[]
                        {
                            '"'
                        }));
                    }
                    else if (text.StartsWith("$path", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Path = text.GetValueInternal("=");
                        }
                    }
                    else if (text.StartsWith("$domain", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Domain = text.GetValueInternal("=");
                        }
                    }
                    else if (text.StartsWith("$port", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string port = (!text.Equals("$port", StringComparison.InvariantCultureIgnoreCase)) ? text.GetValueInternal("=") : "\"\"";
                        if (cookie != null)
                        {
                            cookie.Port = port;
                        }
                    }
                    else
                    {
                        if (cookie != null)
                        {
                            cookieCollection.Add(cookie);
                        }
                        string value2 = string.Empty;
                        int    num2   = text.IndexOf('=');
                        string name;
                        if (num2 == -1)
                        {
                            name = text;
                        }
                        else if (num2 == text.Length - 1)
                        {
                            name = text.Substring(0, num2).TrimEnd(new char[]
                            {
                                ' '
                            });
                        }
                        else
                        {
                            name = text.Substring(0, num2).TrimEnd(new char[]
                            {
                                ' '
                            });
                            value2 = text.Substring(num2 + 1).TrimStart(new char[]
                            {
                                ' '
                            });
                        }
                        cookie = new Cookie(name, value2);
                        if (num != 0)
                        {
                            cookie.Version = num;
                        }
                    }
                }
            }
            if (cookie != null)
            {
                cookieCollection.Add(cookie);
            }
            return(cookieCollection);
        }
Ejemplo n.º 4
0
        private static CookieCollection parseRequest(string value)
        {
            string           str;
            CookieCollection cookieCollections = new CookieCollection();
            Cookie           cookie            = null;
            int num = 0;

            string[] strArrays = CookieCollection.splitCookieHeaderValue(value);
            for (int i = 0; i < (int)strArrays.Length; i++)
            {
                string str1 = strArrays[i].Trim();
                if (str1.Length != 0)
                {
                    if (str1.StartsWith("$version", StringComparison.InvariantCultureIgnoreCase))
                    {
                        num = int.Parse(str1.GetValue('=', true));
                    }
                    else if (str1.StartsWith("$path", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Path = str1.GetValue('=');
                        }
                    }
                    else if (str1.StartsWith("$domain", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookie.Domain = str1.GetValue('=');
                        }
                    }
                    else if (!str1.StartsWith("$port", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cookie != null)
                        {
                            cookieCollections.Add(cookie);
                        }
                        string empty = string.Empty;
                        int    num1  = str1.IndexOf('=');
                        if (num1 == -1)
                        {
                            str = str1;
                        }
                        else if (num1 != str1.Length - 1)
                        {
                            str   = str1.Substring(0, num1).TrimEnd(new char[] { ' ' });
                            empty = str1.Substring(num1 + 1).TrimStart(new char[] { ' ' });
                        }
                        else
                        {
                            str = str1.Substring(0, num1).TrimEnd(new char[] { ' ' });
                        }
                        cookie = new Cookie(str, empty);
                        if (num != 0)
                        {
                            cookie.Version = num;
                        }
                    }
                    else
                    {
                        string str2 = (str1.Equals("$port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : str1.GetValue('='));
                        if (cookie != null)
                        {
                            cookie.Port = str2;
                        }
                    }
                }
            }
            if (cookie != null)
            {
                cookieCollections.Add(cookie);
            }
            return(cookieCollections);
        }