コード例 #1
0
        /// <summary>Sends this request.
        /// Note that this does not block and is thread safe. Instead, OnRequestDone will be called when it's done.</summary>
        public void Send()
        {
            // Clear RDC:
            RedirectionCount = 0;

            // Get the cookie jar:
            CookieJar jar = location.CookieJar;

            if (jar != null)
            {
                // We've got a cookie jar!

                // Set cookie string:
                Package.requestHeaders["cookie"] = jar.GetCookieHeader(location);
            }

            // Got auth?
            if (location.authorization != null)
            {
                // Get bytes:
                byte[] authBytes = System.Text.Encoding.UTF8.GetBytes(location.authorization);

                // Apply the auth header:
                Package.requestHeaders["authorization"] = System.Convert.ToBase64String(authBytes);
            }

            // Request now:
            RequestHeaders = Package.requestHeaders.ToSingleSet();

            BeginRequest(url, Package.request, RequestHeaders);

            // Push this onto the front of our update queue:
            Web.Queue(this);
        }
コード例 #2
0
        /// <summary>Gets the cookie jar for the given domain. Recursively checks parent domains.
        /// Optionally creates one if it wasn't found.</summary>
        public static CookieJar Get(string domain, bool create)
        {
            // If the domain starts with a '.' then ignore it:
            if (domain.StartsWith("."))
            {
                domain = domain.Substring(1);
            }

            DomainData domainData = Cache.GetDomain(domain);
            CookieJar  jar        = domainData.Cookies;

            if (jar != null)
            {
                return(jar);
            }

            // jar not found!

            if (create)
            {
                // Create it here:
                jar = new CookieJar(domainData);
                domainData.Cookies = jar;
                return(jar);
            }

            // Try parent domains:
            int indexOf = domain.IndexOf('.');

            while (indexOf != -1)
            {
                // Chop off the first part:
                domain = domain.Substring(indexOf + 1);

                // Get the next index of:
                indexOf = domain.IndexOf('.');

                if (indexOf != -1)
                {
                    // We still have a dot in the domain - try again:
                    domainData = Cache.GetDomain(domain);
                    jar        = domainData.Cookies;

                    if (jar != null)
                    {
                        return(jar);
                    }
                }
            }

            return(null);
        }
コード例 #3
0
        /// <summary>Sets this cookie.</summary>
        public void SafeSet(Location url)
        {
            if (!SafeToSet(url))
            {
                // Site attempted to set a cookie for another domain.
                return;
            }

            // Note: At this point, cookie.Domain is always available.

            // In you go!
            CookieJar jar = CookieJar.Get(Domain, true);

            jar.Add(this);

            // Save the domain:
            jar.Save();
        }