If you want to modify the headers of a response, you need to use an EventSubscriber. Symphony doesn't have a hook system, but instead uses an event/emitter system. Since it's Symphony driving the request/response cycle, you basically needs to integrate with Symphony to do this.
You could take a look at \Drupal\Core\EventSubscriber\FinishResponseSubscriber
to see how this is done, the gist of it is this:
/**
* Add custom headers.
*/
class HeaderResponseSubscriber implements EventSubscriberInterface {
public function onRespond(FilterResponseEvent $event) {
$response = $event->getResponse();
$response->headers->set('Some-Header', 'some value');
}
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = array('onRespond');
return $events;
}
}
Note in the above code all use statements have been excluded, also you need to register your class as a event_subscriber service, this is done in your module's module_name.services.yml
file like this:
services:
name_of_service:
class: Drupal\Full\Namespaced\Path\To\Class
tags:
- { name: event_subscriber }
You can add arguments (other services) that your class will depend on in the services file like normally.
$build['#attached']['http_header']
to add a custom header. – kenorb Aug 27 '17 at 21:21