private def resultWithVaryHeader()

in facia/app/controllers/FaciaController.scala [204:310]


  private def resultWithVaryHeader(result: CacheableResult, targetedTerritories: Boolean)(implicit
      request: RequestHeader,
  ) =
    withVaryHeader(successful(Cached(CacheTime.Facia)(result)), targetedTerritories)

  private def resultWithVaryAndPreloadHeader(result: CacheableResult, targetedTerritories: Boolean)(implicit
      request: RequestHeader,
  ) =
    withVaryHeader(
      successful(
        Cached(CacheTime.Facia)(result)
          .withPreload(
            Preload.config(request).getOrElse(context.applicationIdentity, Seq.empty),
          )(context, request)
          .withPreconnect(HttpPreconnections.defaultUrls),
      ),
      targetedTerritories,
    )

  private[controllers] def renderFrontPressResult(path: String)(implicit request: RequestHeader): Future[Result] = {
    val futureFaciaPage = getFaciaPage(path)

    /** Europe Beta test: swaps the collections on the Europe network front with those on the hidden europe-beta front
      * for users participating in the test
      */
    val futureFaciaPageWithEuropeBetaTest: Future[Option[(PressedPage, Boolean)]] = {
      if (
        path == "europe" && (ActiveExperiments
          .isParticipating(EuropeBetaFront) || ActiveExperiments.isParticipating(EuropeBetaFrontTest2))
      ) {
        val futureEuropeBetaPage = getFaciaPage("europe-beta")
        for {
          europePage <- futureFaciaPage
          europeBetaPage <- futureEuropeBetaPage
        } yield replaceFaciaPageCollections(europePage, europeBetaPage)
      } else {
        futureFaciaPage
      }
    }

    val customLogFieldMarker = append("requestId", request.headers.get("x-gu-xid").getOrElse("request-id-not-provided"))

    val networkFrontEdition = Edition.allEditions.find(_.networkFrontId == path)
    val deeplyRead = networkFrontEdition.map(deeplyReadAgent.getTrails)

    val futureResult = futureFaciaPageWithEuropeBetaTest.flatMap {
      case Some((faciaPage, _)) if nonHtmlEmail(request) =>
        successful(Cached(CacheTime.RecentlyUpdated)(renderEmail(faciaPage)))
      case Some((faciaPage: PressedPage, targetedTerritories))
          if FaciaPicker.getTier(faciaPage) == RemoteRender
            && !request.isJson =>
        val pageType = PageType(faciaPage, request, context)

        logInfoWithRequestId(
          s"Front Geo Request (212): ${Edition(request).id} ${request.headers.toSimpleMap.getOrElse("X-GU-GeoLocation", "country:row")}",
        )
        withVaryHeader(
          remoteRenderer.getFront(
            ws = ws,
            page = faciaPage,
            pageType = pageType,
            mostViewed = mostViewedAgent.mostViewed(Edition(request)),
            mostCommented = mostViewedAgent.mostCommented,
            mostShared = mostViewedAgent.mostShared,
            deeplyRead = deeplyRead,
          )(request),
          targetedTerritories,
        )
      case Some((faciaPage: PressedPage, targetedTerritories)) if request.isRss =>
        val body = TrailsToRss.fromPressedPage(faciaPage)

        withVaryHeader(
          successful(Cached(CacheTime.Facia)(RevalidatableResult(Ok(body).as("text/xml; charset=utf-8"), body))),
          targetedTerritories,
        )
      case Some((faciaPage: PressedPage, targetedTerritories)) if request.isJson =>
        val result = if (request.forceDCR) {
          logInfoWithRequestId(
            s"Front Geo Request (237): ${Edition(request).id} ${request.headers.toSimpleMap.getOrElse("X-GU-GeoLocation", "country:row")}",
          )
          JsonComponent.fromWritable(
            DotcomFrontsRenderingDataModel(
              page = faciaPage,
              request = request,
              pageType = PageType(faciaPage, request, context),
              mostViewed = mostViewedAgent.mostViewed(Edition(request)),
              mostCommented = mostViewedAgent.mostCommented,
              mostShared = mostViewedAgent.mostShared,
              deeplyRead = deeplyRead,
            ),
          )
        } else JsonFront(faciaPage)
        resultWithVaryHeader(result, targetedTerritories)
      case Some((faciaPage: PressedPage, targetedTerritories)) if request.isEmail || ConfigAgent.isEmailFront(path) =>
        resultWithVaryHeader(renderEmail(faciaPage), targetedTerritories)
      case Some((faciaPage: PressedPage, targetedTerritories)) if TrailsToShowcase.isShowcaseFront(faciaPage) =>
        resultWithVaryHeader(renderShowcaseFront(faciaPage), targetedTerritories)
      case Some((faciaPage: PressedPage, targetedTerritories)) =>
        resultWithVaryAndPreloadHeader(RevalidatableResult.Ok(FrontHtmlPage.html(faciaPage)), targetedTerritories)
      case None => {
        successful(Cached(CacheTime.NotFound)(WithoutRevalidationResult(NotFound)))
      }
    }

    futureResult.failed.foreach { t: Throwable => logErrorWithRequestId(s"Failed rendering $path with $t", t) }
    futureResult
  }