예제 #1
0
        /// <summary>
        /// Handles the published content (if any).
        /// </summary>
        /// <remarks>
        /// Handles "not found", internal redirects, access validation...
        /// things that must be handled in one place because they can create loops
        /// </remarks>
        private void HandlePublishedContent(PublishedRequest request)
        {
            // because these might loop, we have to have some sort of infinite loop detection
            int       i = 0, j = 0;
            const int maxLoop = 8;

            do
            {
                _logger.Debug <PublishedRouter>("HandlePublishedContent: Loop {LoopCounter}", i);

                // handle not found
                if (request.HasPublishedContent == false)
                {
                    request.Is404 = true;
                    _logger.Debug <PublishedRouter>("HandlePublishedContent: No document, try last chance lookup");

                    // if it fails then give up, there isn't much more that we can do
                    if (_contentLastChanceFinder.TryFindContent(request) == false)
                    {
                        _logger.Debug <PublishedRouter>("HandlePublishedContent: Failed to find a document, give up");
                        break;
                    }

                    _logger.Debug <PublishedRouter>("HandlePublishedContent: Found a document");
                }

                // follow internal redirects as long as it's not running out of control ie infinite loop of some sort
                j = 0;
                while (FollowInternalRedirects(request) && j++ < maxLoop)
                {
                }
                if (j == maxLoop) // we're running out of control
                {
                    break;
                }

                // ensure access
                if (request.HasPublishedContent)
                {
                    EnsurePublishedContentAccess(request);
                }

                // loop while we don't have page, ie the redirect or access
                // got us to nowhere and now we need to run the notFoundLookup again
                // as long as it's not running out of control ie infinite loop of some sort
            } while (request.HasPublishedContent == false && i++ < maxLoop);

            if (i == maxLoop || j == maxLoop)
            {
                _logger.Debug <PublishedRouter>("HandlePublishedContent: Looks like we are running into an infinite loop, abort");
                request.PublishedContent = null;
            }

            _logger.Debug <PublishedRouter>("HandlePublishedContent: End");
        }
예제 #2
0
    /// <summary>
    ///     Handles the published content (if any).
    /// </summary>
    /// <param name="request">The request builder.</param>
    /// <remarks>
    ///     Handles "not found", internal redirects ...
    ///     things that must be handled in one place because they can create loops
    /// </remarks>
    private async Task HandlePublishedContent(IPublishedRequestBuilder request)
    {
        // because these might loop, we have to have some sort of infinite loop detection
        int       i = 0, j = 0;
        const int maxLoop = 8;

        do
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("HandlePublishedContent: Loop {LoopCounter}", i);
            }

            // handle not found
            if (request.PublishedContent == null)
            {
                request.SetIs404();
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug("HandlePublishedContent: No document, try last chance lookup");
                }

                // if it fails then give up, there isn't much more that we can do
                if (await _contentLastChanceFinder.TryFindContent(request) == false)
                {
                    if (_logger.IsEnabled(LogLevel.Debug))
                    {
                        _logger.LogDebug("HandlePublishedContent: Failed to find a document, give up");
                    }

                    break;
                }

                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug("HandlePublishedContent: Found a document");
                }
            }

            // follow internal redirects as long as it's not running out of control ie infinite loop of some sort
            j = 0;
            while (FollowInternalRedirects(request) && j++ < maxLoop)
            {
            }

            // we're running out of control
            if (j == maxLoop)
            {
                break;
            }

            // loop while we don't have page, ie the redirect or access
            // got us to nowhere and now we need to run the notFoundLookup again
            // as long as it's not running out of control ie infinite loop of some sort
        }while (request.PublishedContent == null && i++ < maxLoop);

        if (i == maxLoop || j == maxLoop)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("HandlePublishedContent: Looks like we are running into an infinite loop, abort");
            }

            request.SetPublishedContent(null);
        }

        if (_logger.IsEnabled(LogLevel.Debug))
        {
            _logger.LogDebug("HandlePublishedContent: End");
        }
    }