How do I read response headers? I have data in custom response headers that I need to read. I have looked in the Drupal API guide and there is a reference to Response::$headers, but I'm not sure how to exactly use this to read header data.

Edit - to further elaborate what I am trying to accomplish:

I have a form in a custom module that redirects some data in the headers to another page. Here is the code for that:

$response = new RedirectResponse('/path/destination', 302, array(
            "username" =&gt; "value"
          ));
$response-&gt;send();


The redirect is made successfully and the values that I'm pushing to the headers (illustrated by "username" above) are successfully transferred onto the response headers - I can see that with the browser inspector.

What I am now trying to do is read the values of those custom headers, i.e. "username", as a means of pre-populating the username field on my destination page (/path/destination).

As suggested in the answers, I have also done the following:

$response = new ResponseHeaderBag();
$response::get("username");


I also tried:

$response = new ResponseHeaderBag();
$response-&gt;get("username", $default = null, $first = true);


Even though I have both these inclusions on the top of my file:

use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;


I get the following error:

Fatal error: Call to undefined method Drupal\module_name\Form\MyClass::all() in ../vendor/symfony/http-foundation/HeaderBag.php on line 113
Response::$headers is a public property, which means you can access it with $response-&gt;headers, where contains an object of the ResponseHeaderBag class or some inherited class of it.

Essentially, it means you can access the headers using either ResponseHeaderBag::all or ResponseHeaderBag::get($key).