Exemple #1
0
		void SetCookie (string header)
		{
			string name, val;
			Cookie cookie = null;
			CookieParser parser = new CookieParser (header);

			while (parser.GetNextNameValue (out name, out val)) {
				if ((name == null || name == "") && cookie == null)
					continue;

				if (cookie == null) {
					cookie = new Cookie (name, val);
					continue;
				}

				name = name.ToUpper ();
				switch (name) {
				case "COMMENT":
					if (cookie.Comment == null)
						cookie.Comment = val;
					break;
				case "COMMENTURL":
					if (cookie.CommentUri == null)
						cookie.CommentUri = new Uri (val);
					break;
				case "DISCARD":
					cookie.Discard = true;
					break;
				case "DOMAIN":
					if (cookie.Domain == "")
						cookie.Domain = val;
					break;
				case "HTTPONLY":
					cookie.HttpOnly = true;
					break;
				case "MAX-AGE": // RFC Style Set-Cookie2
					if (cookie.Expires == DateTime.MinValue) {
						try {
						cookie.Expires = cookie.TimeStamp.AddSeconds (UInt32.Parse (val));
						} catch {}
					}
					break;
				case "EXPIRES": // Netscape Style Set-Cookie
					if (cookie.Expires != DateTime.MinValue)
						break;

					cookie.Expires = CookieParser.TryParseCookieExpires (val);
					break;
				case "PATH":
					cookie.Path = val;
					break;
				case "PORT":
					if (cookie.Port == null)
						cookie.Port = val;
					break;
				case "SECURE":
					cookie.Secure = true;
					break;
				case "VERSION":
					try {
						cookie.Version = (int) UInt32.Parse (val);
					} catch {}
					break;
				}
			}

			if (cookie == null)
				return;

			if (cookieCollection == null)
				cookieCollection = new CookieCollection ();

			if (cookie.Domain == "")
				cookie.Domain = uri.Host;

			cookieCollection.Add (cookie);
			if (cookie_container != null)
				cookie_container.Add (uri, cookie);
		}
Exemple #2
0
        private void SetCookie(string header)
        {
            Cookie       cookie       = null;
            CookieParser cookieParser = new CookieParser(header);
            string       text;
            string       text2;

            while (cookieParser.GetNextNameValue(out text, out text2))
            {
                if ((text != null && !(text == string.Empty)) || cookie != null)
                {
                    if (cookie == null)
                    {
                        cookie = new Cookie(text, text2);
                    }
                    else
                    {
                        text = text.ToUpper();
                        string text3 = text;
                        switch (text3)
                        {
                        case "COMMENT":
                            if (cookie.Comment == null)
                            {
                                cookie.Comment = text2;
                            }
                            break;

                        case "COMMENTURL":
                            if (cookie.CommentUri == null)
                            {
                                cookie.CommentUri = new System.Uri(text2);
                            }
                            break;

                        case "DISCARD":
                            cookie.Discard = true;
                            break;

                        case "DOMAIN":
                            if (cookie.Domain == string.Empty)
                            {
                                cookie.Domain = text2;
                            }
                            break;

                        case "HTTPONLY":
                            cookie.HttpOnly = true;
                            break;

                        case "MAX-AGE":
                            if (cookie.Expires == DateTime.MinValue)
                            {
                                try
                                {
                                    cookie.Expires = cookie.TimeStamp.AddSeconds(uint.Parse(text2));
                                }
                                catch
                                {
                                }
                            }
                            break;

                        case "EXPIRES":
                            if (!(cookie.Expires != DateTime.MinValue))
                            {
                                cookie.Expires = this.TryParseCookieExpires(text2);
                            }
                            break;

                        case "PATH":
                            cookie.Path = text2;
                            break;

                        case "PORT":
                            if (cookie.Port == null)
                            {
                                cookie.Port = text2;
                            }
                            break;

                        case "SECURE":
                            cookie.Secure = true;
                            break;

                        case "VERSION":
                            try
                            {
                                cookie.Version = (int)uint.Parse(text2);
                            }
                            catch
                            {
                            }
                            break;
                        }
                    }
                }
            }
            if (cookie == null)
            {
                return;
            }
            if (this.cookieCollection == null)
            {
                this.cookieCollection = new CookieCollection();
            }
            if (cookie.Domain == string.Empty)
            {
                cookie.Domain = this.uri.Host;
            }
            this.cookieCollection.Add(cookie);
            if (this.cookie_container != null)
            {
                this.cookie_container.Add(this.uri, cookie);
            }
        }
Exemple #3
0
        void SetCookie(string header)
        {
            string       name, val;
            Cookie       cookie = null;
            CookieParser parser = new CookieParser(header);

            while (parser.GetNextNameValue(out name, out val))
            {
                if ((name == null || name == "") && cookie == null)
                {
                    continue;
                }

                if (cookie == null)
                {
                    cookie = new Cookie(name, val);
                    continue;
                }

                name = name.ToUpper();
                switch (name)
                {
                case "COMMENT":
                    if (cookie.Comment == null)
                    {
                        cookie.Comment = val;
                    }
                    break;

                case "COMMENTURL":
                    if (cookie.CommentUri == null)
                    {
                        cookie.CommentUri = new Uri(val);
                    }
                    break;

                case "DISCARD":
                    cookie.Discard = true;
                    break;

                case "DOMAIN":
                    if (cookie.Domain == "")
                    {
                        cookie.Domain = val;
                    }
                    break;

                case "MAX-AGE":                 // RFC Style Set-Cookie2
                    if (cookie.Expires == DateTime.MinValue)
                    {
                        try {
                            cookie.Expires = cookie.TimeStamp.AddSeconds(UInt32.Parse(val));
                        } catch {}
                    }
                    break;

                case "EXPIRES":                 // Netscape Style Set-Cookie
                    if (cookie.Expires != DateTime.MinValue)
                    {
                        break;
                    }

                    cookie.Expires = TryParseCookieExpires(val);
                    break;

                case "PATH":
                    cookie.Path = val;
                    break;

                case "PORT":
                    if (cookie.Port == null)
                    {
                        cookie.Port = val;
                    }
                    break;

                case "SECURE":
                    cookie.Secure = true;
                    break;

                case "VERSION":
                    try {
                        cookie.Version = (int)UInt32.Parse(val);
                    } catch {}
                    break;
                }
            }

            if (cookieCollection == null)
            {
                cookieCollection = new CookieCollection();
            }

            if (cookie.Domain == "")
            {
                cookie.Domain = uri.Host;
            }

            cookieCollection.Add(cookie);
            if (cookie_container != null)
            {
                cookie_container.Add(uri, cookie);
            }
        }
        private void SetCookie(string header)
        {
            Cookie       cookie       = null;
            CookieParser cookieParser = new CookieParser(header);
            string       name;
            string       val;

            while (cookieParser.GetNextNameValue(out name, out val))
            {
                if ((name == null || name == string.Empty) && cookie == null)
                {
                    continue;
                }
                if (cookie == null)
                {
                    cookie = new Cookie(name, val);
                    continue;
                }
                name = name.ToUpper();
                switch (name)
                {
                case "COMMENT":
                    if (cookie.Comment == null)
                    {
                        cookie.Comment = val;
                    }
                    break;

                case "COMMENTURL":
                    if (cookie.CommentUri == null)
                    {
                        cookie.CommentUri = new Uri(val);
                    }
                    break;

                case "DISCARD":
                    cookie.Discard = true;
                    break;

                case "DOMAIN":
                    if (cookie.Domain == string.Empty)
                    {
                        cookie.Domain = val;
                    }
                    break;

                case "HTTPONLY":
                    cookie.HttpOnly = true;
                    break;

                case "MAX-AGE":
                    if (cookie.Expires == DateTime.MinValue)
                    {
                        try
                        {
                            cookie.Expires = cookie.TimeStamp.AddSeconds(uint.Parse(val));
                        }
                        catch
                        {
                        }
                    }
                    break;

                case "EXPIRES":
                    if (!(cookie.Expires != DateTime.MinValue))
                    {
                        cookie.Expires = TryParseCookieExpires(val);
                    }
                    break;

                case "PATH":
                    cookie.Path = val;
                    break;

                case "PORT":
                    if (cookie.Port == null)
                    {
                        cookie.Port = val;
                    }
                    break;

                case "SECURE":
                    cookie.Secure = true;
                    break;

                case "VERSION":
                    try
                    {
                        cookie.Version = (int)uint.Parse(val);
                    }
                    catch
                    {
                    }
                    break;
                }
            }
            if (cookie != null)
            {
                if (cookieCollection == null)
                {
                    cookieCollection = new CookieCollection();
                }
                if (cookie.Domain == string.Empty)
                {
                    cookie.Domain = uri.Host;
                }
                cookieCollection.Add(cookie);
                if (cookie_container != null)
                {
                    cookie_container.Add(uri, cookie);
                }
            }
        }