Пример #1
0
        private CookieState(CookieState source)
        {
            Contract.Requires(source != null);

            this._name = source._name;
            if (source._values != null)
            {
                this.Values.Add(source._values);
            }
        }
Пример #2
0
        private CookieState(CookieState source)
        {
            Contract.Requires(source != null);

            this._name = source._name;
            if (source._values != null)
            {
                this.Values.Add(source._values);
            }
        }
Пример #3
0
        public CookieState this[string name]
        {
            get
            {
                if (String.IsNullOrEmpty(name))
                {
                    return(null);
                }

                CookieState cookie = this.Cookies.FirstOrDefault(c => String.Equals(c.Name, name, StringComparison.OrdinalIgnoreCase));
                if (cookie == null)
                {
                    cookie = new CookieState(name, String.Empty);
                    this.Cookies.Add(cookie);
                }
                return(cookie);
            }
        }
        public CookieState this[string name]
        {
            get
            {
                if (String.IsNullOrEmpty(name))
                {
                    return null;
                }

                CookieState cookie = this.Cookies.FirstOrDefault(c => String.Equals(c.Name, name, StringComparison.OrdinalIgnoreCase));
                if (cookie == null)
                {
                    cookie = new CookieState(name, String.Empty);
                    this.Cookies.Add(cookie);
                }
                return cookie;
            }
        }
 public CookieHeaderValue(string name, NameValueCollection values)
 {
     CookieState cookie = new CookieState(name, values);
     this.Cookies.Add(cookie);
 }
 public CookieHeaderValue(string name, string value)
 {
     CookieState cookie = new CookieState(name, value);
     this.Cookies.Add(cookie);
 }
        private static bool ParseCookieSegment(CookieHeaderValue instance, string segment)
        {
            if (String.IsNullOrWhiteSpace(segment))
            {
                return true;
            }

            string[] nameValue = segment.Split(nameValueSeparator, 2);
            if (nameValue.Length < 1 || String.IsNullOrWhiteSpace(nameValue[0]))
            {
                return false;
            }

            string name = nameValue[0].Trim();
            if (String.Equals(name, ExpiresToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                DateTimeOffset expires;
                if (FormattingUtilities.TryParseDate(value, out expires))
                {
                    instance.Expires = expires;
                    return true;
                }
                return false;
            }
            else if (String.Equals(name, MaxAgeToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                int maxAge;
                if (FormattingUtilities.TryParseInt32(value, out maxAge))
                {
                    instance.MaxAge = new TimeSpan(0, 0, maxAge);
                    return true;
                }
                return false;
            }
            else if (String.Equals(name, DomainToken, StringComparison.OrdinalIgnoreCase))
            {
                instance.Domain = GetSegmentValue(nameValue, null);
                return true;
            }
            else if (String.Equals(name, PathToken, StringComparison.OrdinalIgnoreCase))
            {
                instance.Path = GetSegmentValue(nameValue, DefaultPath);
                return true;
            }
            else if (String.Equals(name, SecureToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                if (!String.IsNullOrWhiteSpace(value))
                {
                    return false;
                }
                instance.Secure = true;
                return true;
            }
            else if (String.Equals(name, HttpOnlyToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                if (!String.IsNullOrWhiteSpace(value))
                {
                    return false;
                }
                instance.HttpOnly = true;
                return true;
            }
            else
            {
                string value = GetSegmentValue(nameValue, null);

                // We read the cookie segment as form data
                try
                {
                    FormDataCollection formData = new FormDataCollection(value);
                    NameValueCollection values = formData.ReadAsNameValueCollection();
                    CookieState cookie = new CookieState(name, values);
                    instance.Cookies.Add(cookie);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
Пример #8
0
        public CookieHeaderValue(string name, NameValueCollection values)
        {
            CookieState cookie = new CookieState(name, values);

            this.Cookies.Add(cookie);
        }
Пример #9
0
        public CookieHeaderValue(string name, string value)
        {
            CookieState cookie = new CookieState(name, value);

            this.Cookies.Add(cookie);
        }
Пример #10
0
        private static bool ParseCookieSegment(CookieHeaderValue instance, string segment)
        {
            if (String.IsNullOrWhiteSpace(segment))
            {
                return(true);
            }

            string[] nameValue = segment.Split(nameValueSeparator, 2);
            if (nameValue.Length < 1 || String.IsNullOrWhiteSpace(nameValue[0]))
            {
                return(false);
            }

            string name = nameValue[0].Trim();

            if (String.Equals(name, ExpiresToken, StringComparison.OrdinalIgnoreCase))
            {
                string         value = GetSegmentValue(nameValue, null);
                DateTimeOffset expires;
                if (FormattingUtilities.TryParseDate(value, out expires))
                {
                    instance.Expires = expires;
                    return(true);
                }
                return(false);
            }
            else if (String.Equals(name, MaxAgeToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                int    maxAge;
                if (FormattingUtilities.TryParseInt32(value, out maxAge))
                {
                    instance.MaxAge = new TimeSpan(0, 0, maxAge);
                    return(true);
                }
                return(false);
            }
            else if (String.Equals(name, DomainToken, StringComparison.OrdinalIgnoreCase))
            {
                instance.Domain = GetSegmentValue(nameValue, null);
                return(true);
            }
            else if (String.Equals(name, PathToken, StringComparison.OrdinalIgnoreCase))
            {
                instance.Path = GetSegmentValue(nameValue, DefaultPath);
                return(true);
            }
            else if (String.Equals(name, SecureToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                if (!String.IsNullOrWhiteSpace(value))
                {
                    return(false);
                }
                instance.Secure = true;
                return(true);
            }
            else if (String.Equals(name, HttpOnlyToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                if (!String.IsNullOrWhiteSpace(value))
                {
                    return(false);
                }
                instance.HttpOnly = true;
                return(true);
            }
            else
            {
                string value = GetSegmentValue(nameValue, null);

                // We read the cookie segment as form data
                try
                {
                    FormDataCollection  formData = new FormDataCollection(value);
                    NameValueCollection values   = formData.ReadAsNameValueCollection();
                    CookieState         cookie   = new CookieState(name, values);
                    instance.Cookies.Add(cookie);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }