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

Throw InvalidArgumentException when an incorrect headers array is provided #2942

Merged
merged 2 commits into from Oct 17, 2021

Conversation

TimWolla
Copy link
Contributor

@TimWolla TimWolla commented Oct 13, 2021

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
@@ -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
Contributor Author

@TimWolla TimWolla Oct 13, 2021

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 Oct 13, 2021
@GrahamCampbell GrahamCampbell merged commit 399c0ea into guzzle:master Oct 17, 2021
23 checks passed
@GrahamCampbell
Copy link
Member

GrahamCampbell commented Oct 17, 2021

Thank you. Your keen eye is much appreciated. 🍻

@TimWolla TimWolla deleted the header-array-validation branch Oct 17, 2021
@TimWolla
Copy link
Contributor Author

TimWolla commented Oct 17, 2021

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

@GrahamCampbell
Copy link
Member

GrahamCampbell commented Oct 18, 2021

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

@TimWolla
Copy link
Contributor Author

TimWolla commented Oct 18, 2021

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

@GrahamCampbell
Copy link
Member

GrahamCampbell commented Oct 18, 2021

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.

None yet

2 participants