i want to retrieve all headers sent in the http facade in laravel how?

The docs for the client outline a way that you can assert a specific header is present, and you can optionally assert the value too; https://laravel.com/docs/8.x/http-client#inspecting-requests.

Sounds like you want to dump out all the headers though.

If we look in the documentation, when you are asserting a request was sent, you are passed an instance of Illuminate\Http\Client\Request. If we take a look at Illuminate\Http\Client\Request there is a public method for getting all the headers:

 * Get the request headers.
 * @return array
public function headers()
    return collect($this->request->getHeaders())->mapWithKeys(function ($values, $header) {
        return [$header => $values];

So in your test, you could do something like this:


//... your test

Http::assertSent(function ($request) {

    // replace this with an actual assertion but it’s needed to print the dump out
    return true;

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top