Skip to content

[7.x] Add ability to check for multiple request headers when using HTTP Client - #32462

Merged
taylorotwell merged 2 commits into
laravel:7.xfrom
mattkingshott:7.x
Apr 20, 2020
Merged

[7.x] Add ability to check for multiple request headers when using HTTP Client#32462
taylorotwell merged 2 commits into
laravel:7.xfrom
mattkingshott:7.x

Conversation

@mattkingshott

Copy link
Copy Markdown
Contributor

This PR adds a hasHeaders() method to Illuminate/Http/Client/Request.php, and may be used to more succinctly check if an array of headers is present when inspecting requests. Under the hood, the hasHeaders method simply defers to the already present hasHeader method.

Before:

Http:withHeaders([
    'X-Test-Header' => 'foo',
    'X-Test-ArrayHeader' => ['bar', 'baz'],
]);

Http:assertSent(function ($request) {
    return $request->hasHeader('X-Test-Header', 'foo') &&
           $request->hasHeader('X-Test-ArrayHeader', ['bar', 'baz']);
});

After

Http:withHeaders($headers = [
    'X-Test-Header' => 'foo',
    'X-Test-ArrayHeader' => ['bar', 'baz'],
]);

Http:assertSent(function ($request) {
    return $request->hasHeaders($headers);
});

// or with PHP 7.4 arrow functions...

Http:assertSent(fn ($request) => $request->hasHeaders($headers));

@taylorotwell
taylorotwell merged commit 186a1b3 into laravel:7.x Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants