class AddHTTPHeaders in HTTP Response Headers 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/AddHTTPHeaders.php \Drupal\http_response_headers\EventSubscriber\AddHTTPHeaders
- 2.0.x src/EventSubscriber/AddHTTPHeaders.php \Drupal\http_response_headers\EventSubscriber\AddHTTPHeaders
Provides AddHTTPHeaders.
Hierarchy
- class \Drupal\http_response_headers\EventSubscriber\AddHTTPHeaders implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of AddHTTPHeaders
1 string reference to 'AddHTTPHeaders'
1 service uses AddHTTPHeaders
File
- src/
EventSubscriber/ AddHTTPHeaders.php, line 17 - Contains \Drupal\http_response_headers\EventSubscriber\AddHTTPHeaders.
Namespace
Drupal\http_response_headers\EventSubscriberView source
class AddHTTPHeaders implements EventSubscriberInterface {
/**
* Sets extra HTTP headers.
*/
public function onRespond(FilterResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
$response = $event
->getResponse();
$config = \Drupal::config('http_response_headers.settings');
// Security HTTP headers.
$security = $config
->get('security');
foreach ($security as $param => $value) {
if (!empty($value)) {
$response->headers
->set($param, $value);
}
}
$authenticated_only = $config
->get('performance_authenticated_only');
$current_user = \Drupal::currentUser();
// Performance HTTP headers.
if ($authenticated_only && !$current_user
->isAnonymous()) {
$performance = $config
->get('performance');
foreach ($performance as $param => $value) {
if (!empty($value)) {
$response->headers
->set($param, $value);
}
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = [
'onRespond',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddHTTPHeaders:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
AddHTTPHeaders:: |
public | function | Sets extra HTTP headers. |