Skip to content

Throw InvalidArgumentException when an incorrect headers array is provided#2942

Merged
GrahamCampbell merged 2 commits intoguzzle:masterfrom
WoltLab:header-array-validation
Oct 17, 2021
Merged

Throw InvalidArgumentException when an incorrect headers array is provided#2942
GrahamCampbell merged 2 commits intoguzzle:masterfrom
WoltLab:header-array-validation

Conversation

@TimWolla
Copy link
Copy Markdown
Contributor

As discussed in PR #2916 after it was merged an InvalidArgumentException is
more fitting, as passing an invalid headers array is a clear programming
error that needs to be fixed and not caught.

This is consistent with the validation of the other options, e.g. when using
multipart and form_params at the same time.

see #2916
see a2b8dd1

/cc @GrahamCampbell; thanks

… provided

As discussed in PR guzzle#2916 after it was merged an `InvalidArgumentException` is
more fitting, as passing an invalid `headers` array is a clear programming
error that needs to be fixed and not caught.

This is consistent with the validation of the other options, e.g. when using
`multipart` and `form_params` at the same time.

see guzzle#2916
see a2b8dd1
Comment thread src/Client.php
@@ -346,7 +345,7 @@ private function applyOptions(RequestInterface $request, array &$options): Reque

if (isset($options['headers'])) {
if (array_keys($options['headers']) === range(0, count($options['headers']) - 1)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: This could be array_is_list() in PHP 8.1 / by importing Symfony's symfony/polyfill-php81.

@TimWolla TimWolla force-pushed the header-array-validation branch from b4376c8 to 62ca561 Compare October 13, 2021 15:46
@GrahamCampbell GrahamCampbell merged commit 399c0ea into guzzle:master Oct 17, 2021
@GrahamCampbell
Copy link
Copy Markdown
Member

Thank you. Your keen eye is much appreciated. 🍻

@TimWolla TimWolla deleted the header-array-validation branch October 17, 2021 13:42
@TimWolla
Copy link
Copy Markdown
Contributor Author

My pleasure. Happy to give back to libraries we are relying on, even if it's just the little things.

@GrahamCampbell
Copy link
Copy Markdown
Member

6.4.0 has now been released, including this fix. :)

@TimWolla
Copy link
Copy Markdown
Contributor Author

7.4.0 you mean 😛 I've already seen it, thanks.

@GrahamCampbell
Copy link
Copy Markdown
Member

yep 😆

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