예제 #1
0
        /// <summary>Checks if headers are available yet and handles them if they are.</summary>
        private void HandleHeaders()
        {
                        #if UNITY_2017_1_OR_NEWER
            // Back to the old format, which unfortunately drops headers like Set-Cookie and builds the header set repeatedly.
            var headers = WWWRequest.GetResponseHeaders();
            if (headers == null || headers.Count == 0)
            {
                return;
            }
            Package.responseHeaders.LoadFrom(headers, (int)WWWRequest.responseCode);
            Package.ReceivedHeaders();
            bool redirect = false;
                        #else
            string rawHeaderString = ResponseHeaderString;

            if (string.IsNullOrEmpty(rawHeaderString))
            {
                // Not available yet.
                return;
            }

            // Received headers:
            bool redirect = Package.ReceivedHeaders(rawHeaderString);
                        #endif

            if (redirect)
            {
                // Redirection. We'll most likely be making another request, unless we've redirected too many times:
                RedirectionCount++;

                if (RedirectionCount >= 20)
                {
                    // Failed. Too many redirects.
                    Package.statusCode = ErrorHandlers.TooManyRedirects;
                }
                else
                {
                    // Redirect now (note that ready state was unchanged - redirects are supposed to be silent):
                    Duration = 0f;

                    // Get the location:
                    string redirectedTo = Package.responseHeaders["location"];

                    // Set redir to:
                    Package.redirectedTo = new Location(redirectedTo, location);

                    // Get absolute:
                    redirectedTo = Package.redirectedTo.absoluteNoHash;

                    if (string.IsNullOrEmpty(redirectedTo) || redirectedTo.Trim() == "")
                    {
                        // Pop it from the update queue:
                        Remove();

                        // Failed!
                        Package.Failed(500);
                    }
                    else
                    {
                        if (Package.statusCode == 307 || Package.statusCode == 308)
                        {
                            // Resend as-is to the new URI:
                            BeginRequest(redirectedTo, Package.request, RequestHeaders);
                        }
                        else
                        {
                            // GET request to the new URI:
                            BeginRequest(redirectedTo, null, RequestHeaders);
                        }

                        return;
                    }
                }
            }

                        #if !MOBILE && !UNITY_WEBGL && !UNITY_2017_1_OR_NEWER && !UNITY_TVOS
            //  We might be streaming video content.
            if (ContentType == "video/ogg")
            {
                Movie = WWWRequest.movie;
            }
                        #endif
        }
예제 #2
0
        /// <summary>Checks if headers are available yet and handles them if they are.</summary>
        private void HandleHeaders()
        {
            string rawHeaderString = ResponseHeaderString;

            if (string.IsNullOrEmpty(rawHeaderString))
            {
                // Not available yet.
                return;
            }

            // Received headers:
            bool redirect = Package.ReceivedHeaders(rawHeaderString);

            if (redirect)
            {
                // Redirection. We'll most likely be making another request, unless we've redirected too many times:
                RedirectionCount++;

                if (RedirectionCount >= 20)
                {
                    // Failed. Too many redirects.
                    Package.statusCode = ErrorHandlers.TooManyRedirects;
                }
                else
                {
                    // Redirect now (note that ready state was unchanged - redirects are supposed to be silent):
                    Duration = 0f;

                    // Get the location:
                    string redirectedTo = Package.responseHeaders["location"];

                    // Set redir to:
                    Package.redirectedTo = new Location(redirectedTo, location);

                    // Get absolute:
                    redirectedTo = Package.redirectedTo.absoluteNoHash;

                    if (string.IsNullOrEmpty(redirectedTo) || redirectedTo.Trim() == "")
                    {
                        // Pop it from the update queue:
                        Remove();

                        // Failed!
                        Package.Failed(500);
                    }
                    else
                    {
                        if (Package.statusCode == 307 || Package.statusCode == 308)
                        {
                            // Resend as-is to the new URI:
                            BeginRequest(redirectedTo, Package.request, RequestHeaders);
                        }
                        else
                        {
                            // GET request to the new URI:
                            BeginRequest(redirectedTo, null, RequestHeaders);
                        }

                        return;
                    }
                }
            }

                        #if !MOBILE && !UNITY_WEBGL
            //  We might be streaming video content.
            if (ContentType == "video/ogg")
            {
                Movie = WWWRequest.GetMovieTexture();
            }
                        #endif
        }