TIL: How do you add a header to a separate Response in a Controller->Action in Neos Flow?

Note: Since the Flow 7.0 release, the ComponentParameter methods are replaced, with PSR-15 middleware. Read the changelog for more details 🙂

https://flowframework.readthedocs.io/en/7.0/TheDefinitiveGuide/PartV/ReleaseNotes/700.html#psr-15-compatible-middleware-chain


I needed to send a number of Cache-* and Content-* header while working on a project where download was done in my own DowloadController.

I’m using PHP Framework Neos Flow for this project.

Since Neos Flow 6, the PSR-7 has been implemented and I can no longer set it directly on the $this->response object.

Instead, headers are added to a Component being executed in the rendering. So, adding a header with a value is done like this

$this->response->setComponentParameter(SetHeaderComponent::class, 'Cache-control', 'private');

Inside your action – adding several is one per line