Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 20, 2020
Merged

Conversation

mattkingshott
Copy link
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