Ejemplo n.º 1
0
        /// <summary>Gets a <see cref="T:System.Net.CookieCollection" /> that contains the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</summary>
        /// <returns>A <see cref="T:System.Net.CookieCollection" /> that contains the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</returns>
        /// <param name="uri">The URI of the <see cref="T:System.Net.Cookie" /> instances desired. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="uri" /> is null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public CookieCollection GetCookies(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            CheckExpiration();
            CookieCollection cookieCollection = new CookieCollection();

            if (cookies == null)
            {
                return(cookieCollection);
            }
            foreach (Cookie cooky in cookies)
            {
                string domain = cooky.Domain;
                if (CheckDomain(domain, uri.Host, cooky.ExactDomain) && (cooky.Port.Length <= 0 || cooky.Ports == null || uri.Port == -1 || Array.IndexOf(cooky.Ports, uri.Port) != -1))
                {
                    string path         = cooky.Path;
                    string absolutePath = uri.AbsolutePath;
                    if ((!(path != string.Empty) || !(path != "/") || !(absolutePath != path) || (absolutePath.StartsWith(path) && (path[path.Length - 1] == '/' || absolutePath.Length <= path.Length || absolutePath[path.Length] == '/'))) && (!cooky.Secure || !(uri.Scheme != "https")))
                    {
                        cookieCollection.Add(cooky);
                    }
                }
            }
            cookieCollection.Sort();
            return(cookieCollection);
        }
Ejemplo n.º 2
0
        /// <summary>Gets a <see cref="T:System.Net.CookieCollection" /> that contains the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</summary>
        /// <returns>A <see cref="T:System.Net.CookieCollection" /> that contains the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</returns>
        /// <param name="uri">The URI of the <see cref="T:System.Net.Cookie" /> instances desired. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="uri" /> is null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public CookieCollection GetCookies(System.Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            this.CheckExpiration();
            CookieCollection cookieCollection = new CookieCollection();

            if (this.cookies == null)
            {
                return(cookieCollection);
            }
            foreach (object obj in this.cookies)
            {
                Cookie cookie = (Cookie)obj;
                string domain = cookie.Domain;
                if (CookieContainer.CheckDomain(domain, uri.Host, cookie.ExactDomain))
                {
                    if (cookie.Port.Length <= 0 || cookie.Ports == null || uri.Port == -1 || Array.IndexOf <int>(cookie.Ports, uri.Port) != -1)
                    {
                        string path         = cookie.Path;
                        string absolutePath = uri.AbsolutePath;
                        if (path != string.Empty && path != "/" && absolutePath != path)
                        {
                            if (!absolutePath.StartsWith(path))
                            {
                                continue;
                            }
                            if (path[path.Length - 1] != '/' && absolutePath.Length > path.Length && absolutePath[path.Length] != '/')
                            {
                                continue;
                            }
                        }
                        if (!cookie.Secure || !(uri.Scheme != "https"))
                        {
                            cookieCollection.Add(cookie);
                        }
                    }
                }
            }
            cookieCollection.Sort();
            return(cookieCollection);
        }
Ejemplo n.º 3
0
        public CookieCollection GetCookies(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            CheckExpiration();
            CookieCollection coll = new CookieCollection();

            if (cookies == null)
            {
                return(coll);
            }

            foreach (Cookie cookie in cookies)
            {
                string domain = cookie.Domain;
                if (cookie.Version == 1)
                {
                    if (!CheckDomain_RFC2109(domain, uri.Host))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!CheckDomain(domain, uri.Host, !cookie.HasDomain))
                    {
                        continue;
                    }
                }

                if (cookie.Port.Length > 0 && cookie.Ports != null && uri.Port != -1)
                {
                    if (Array.IndexOf(cookie.Ports, uri.Port) == -1)
                    {
                        continue;
                    }
                }

                string path    = cookie.Path;
                string uripath = uri.AbsolutePath;
                if (path != "" && path != "/")
                {
                    if (uripath != path)
                    {
                        if (!uripath.StartsWith(path))
                        {
                            continue;
                        }

                        if (path [path.Length - 1] != '/' && uripath.Length > path.Length &&
                            uripath [path.Length] != '/')
                        {
                            continue;
                        }
                    }
                }

                if (cookie.Secure && uri.Scheme != "https")
                {
                    continue;
                }

                coll.Add(cookie);
            }

            coll.Sort();
            return(coll);
        }
Ejemplo n.º 4
0
		public CookieCollection GetCookies (Uri uri)
		{
			if (uri == null)
				throw new ArgumentNullException ("uri");

			CheckExpiration ();
			CookieCollection coll = new CookieCollection ();
			if (cookies == null)
				return coll;

			foreach (Cookie cookie in cookies) {
				string domain = cookie.Domain;
				if (!CheckDomain (domain, uri.Host, cookie.ExactDomain))
					continue;

				if (cookie.Port.Length > 0 && cookie.Ports != null && uri.Port != -1) {
					if (Array.IndexOf (cookie.Ports, uri.Port) == -1)
						continue;
				}

				string path = cookie.Path;
				string uripath = uri.AbsolutePath;
				if (path != "" && path != "/") {
					if (uripath != path) {
						if (!uripath.StartsWith (path))
							continue;

						if (path [path.Length - 1] != '/' && uripath.Length > path.Length &&
						    uripath [path.Length] != '/')
							continue;
					}
				}

				if (cookie.Secure && uri.Scheme != "https")
					continue;

				coll.Add (cookie);
			}

			coll.Sort ();
			return coll;
		}