/**
  * Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file.
  *
  * @param int $chunk_id
  *  Optional ID of the sitemap chunk. If none provided, the first chunk or
  *  the sitemap index is fetched.
  *
  * @throws NotFoundHttpException
  *
  * @return object
  *  Returns an XML response.
  */
 public function getSitemap($chunk_id = NULL)
 {
     $output = $this->generator->getSitemap($chunk_id);
     if (!$output) {
         throw new NotFoundHttpException();
     }
     // Display sitemap with correct xml header.
     $response = new CacheableResponse($output, Response::HTTP_OK, ['content-type' => 'application/xml']);
     $meta_data = $response->getCacheableMetadata();
     $meta_data->addCacheTags(['simple_sitemap']);
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Sets a header.
  */
 public function setHeader(Request $request)
 {
     $query = $request->query->all();
     $response = new CacheableResponse();
     $response->headers->set($query['name'], $query['value']);
     $response->getCacheableMetadata()->addCacheContexts(['url.query_args:name', 'url.query_args:value']);
     $response->setContent($this->t('The following header was set: %name: %value', array('%name' => $query['name'], '%value' => $query['value'])));
     return $response;
 }