final public async function getResponseAsync()

in src/site/controllers/NonRoutableWebPageController.php [94:203]


  final public async function getResponseAsync(
    ResponseInterface $response,
  ): Awaitable<ResponseInterface> {
    await $this->beforeResponseAsync();
    concurrent {
      $title = await $this->getTitleAsync();
      $content = await $this->getContentPaneAsync();
    }
    $content->appendChild($this->getFooter());

    $extra_class = $this->getExtraBodyClass();
    $body_class = $this->getBodyClass($extra_class);
    $google_analytics = null;
    $open_search = null;
    $require_secure = false;

    $canonical_url = 'http://docs.hhvm.com'.$this->getRequestedPath();
    switch ($this->getRequestedHost()) {
      case 'beta.docs.hhvm.com':
        throw new RedirectException($canonical_url);
      case 'docs.hhvm.com':
        $google_analytics =
          <script:google_analytics trackingID="UA-49208336-3" />;
        $open_search =
          <link
            rel="search"
            type="application/opensearchdescription+xml"
            href="/search.xml"
          />;
        $require_secure = true;
        break;
      case 'staging.docs.hhvm.com':
        $require_secure = true;
        break;
      default: // probably dev environment
        break;
    }

    if ($require_secure) {
      $this->requireSecureConnection();
    }

    $xhp =
      <doctype>
        <html>
          <head>
            <title>{$title}</title>
            <meta charset="utf-8" />
            <meta
              name="viewport"
              content="width=device-width, initial-scale=1.0"
            />
            <link rel="shortcut icon" href="/favicon.png" />

            <meta property="og:type" content="website" />
            <meta property="og:url" content={$canonical_url} />
            <meta property="og:title" content={$title} />
            <meta property="og:description" content="Offical documentation for Hack and HHVM" />
            <meta property="og:image" content="https://docs.hhvm.com/hack_logo_medium.png" />

            {$open_search}
            <comment>
              Build ID: {LocalConfig::getBuildID()}
            </comment>
            <static_res:stylesheet path="/css/main.css" media="screen" />
            <link
              href=
                "https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic|Roboto:700"
              rel="stylesheet"
            />
            {$google_analytics}
            <link
              href=
                "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github-gist.min.css"
              rel="stylesheet"
              type="text/css"
            />
            <script
              src=
                "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"
            />
          </head>
          <body class={$body_class}>
            {$this->getHeader()}
            {$this->getSideNav()}
            {$content}
            {$this->getEagerFetchScript()}
          </body>
        </html>
      </doctype>;
    $xhp->setContext('ServerRequestInterface', $this->request);
    $html = await $xhp->toStringAsync();

    await $response->getBody()->writeAllAsync($html);
    $response = $response
      ->withStatus($this->getStatusCode())
      ->withHeader(
        'Cache-Control',
        vec['max-age=60'],
      ); // enough for pre-fetching :)

    if ($require_secure) {
      $response = $response->withHeader(
        'Strict-Transport-Security',
        vec['max-age='.(60 * 60 * 24 * 28)], // 4 weeks
      );
    }

    return $response;
  }