AggregatorTestRssController.php in Zircon Profile 8.0        
                          
                  
                        
  
  
  
File
  core/modules/aggregator/tests/modules/aggregator_test/src/Controller/AggregatorTestRssController.php
  
    View source  
  <?php
namespace Drupal\aggregator_test\Controller;
use Drupal\Component\Datetime\DateTimePlus;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Component\Utility\Crypt;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
class AggregatorTestRssController extends ControllerBase {
  
  public function testFeed($use_last_modified, $use_etag, Request $request) {
    $response = new Response();
    $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
    $etag = Crypt::hashBase64($last_modified);
    $if_modified_since = strtotime($request->server
      ->get('HTTP_IF_MODIFIED_SINCE'));
    $if_none_match = stripslashes($request->server
      ->get('HTTP_IF_NONE_MATCH'));
    
    if ($use_last_modified) {
      $response->headers
        ->set('Last-Modified', gmdate(DateTimePlus::RFC7231, $last_modified));
    }
    if ($use_etag) {
      $response->headers
        ->set('ETag', $etag);
    }
    
    if ($last_modified == $if_modified_since || $etag == $if_none_match) {
      $response
        ->setStatusCode(304);
      return $response;
    }
    
    $response->headers
      ->set('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
    $response->headers
      ->set('Cache-Control', 'must-revalidate');
    $response->headers
      ->set('Content-Type', 'application/rss+xml; charset=utf-8');
    
    $file_name = drupal_get_path('module', 'aggregator_test') . '/aggregator_test_rss091.xml';
    $handle = fopen($file_name, 'r');
    $feed = fread($handle, filesize($file_name));
    fclose($handle);
    $response
      ->setContent($feed);
    return $response;
  }
  
  public function testRedirect() {
    return $this
      ->redirect('aggregator_test.feed', [], [], 301);
  }
}