/// <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 void 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 { _logger.LogDebug("HandlePublishedContent: Loop {LoopCounter}", i); // handle not found if (request.PublishedContent == null) { request.SetIs404(); _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 (_contentLastChanceFinder.TryFindContent(request) == false) { _logger.LogDebug("HandlePublishedContent: Failed to find a document, give up"); break; } _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) { _logger.LogDebug("HandlePublishedContent: Looks like we are running into an infinite loop, abort"); request.SetPublishedContent(null); } _logger.LogDebug("HandlePublishedContent: End"); }