Throw exception if you are using all wrong headers#2916
Conversation
GrahamCampbell
left a comment
There was a problem hiding this comment.
It would be also good to add some additional validation in the psr7 class to ensure headers are actually of type array<string, string>.
|
Yeah. I agree. But it is a bit tricky. Let's discuss that further on the psr7 repo |
|
|
||
| if (isset($options['headers'])) { | ||
| if (array_keys($options['headers']) === range(0, count($options['headers']) - 1)) { | ||
| throw new RequestException('The headers array must have header name as keys.', $request); |
There was a problem hiding this comment.
My understanding is that this PR is not yet in any release: Should this exception be changed to InvalidArgumentException instead? I seems to be more fitting.
There was a problem hiding this comment.
I think this was chosen for consistency with what similar code here does. I'm open to review this for Guzzle 8.
There was a problem hiding this comment.
@GrahamCampbell Pinging in case you didn't see my response to make sure you see this before an eventual new release.
There was a problem hiding this comment.
Thanks for the ping (I had to clear all my notifications coz thousands built up and I was unable to prioritise effectively). This isn't tagged yet, right? What you are saying sounds reasonable to me. Are you able to send a PR over, so we can get this resolved before the 6.4.0 tag? :)
There was a problem hiding this comment.
Sure, I will get right to it.
… 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
… provided (#2942) * Throw `InvalidArgumentException` when an incorrect `headers` array is provided 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 * Remove obsolete import in Client.php / ClientTest.php
This will fix #2911
Note that this only thrown an exception if you are using all wrong headers. Ie, it check if you send a list or a map.