willdurand / Negotiation

Content Negotiation tools for PHP.
https://williamdurand.fr/Negotiation/
MIT License
1.41k stars 62 forks source link

Skip invalid headers #85

Closed neural-wetware closed 7 years ago

neural-wetware commented 7 years ago

Commit 4e4802509d599d7be6cef919c5e79b3324cb34b4 silently skips invalid headers. I want this library to catch invalid headers so I can 406. It seems silly that I should have to parse the headers again to determine if they are invalid when the library is already doing this.

What do you think about reversing this change or adding a flag to getBest() to enable/disable this? I'm willing to implement this change.

willdurand commented 7 years ago

Hey @neural-wetware, that is very unfortunate. Sorry for that :(

What we might do is having a (static?) flag or a constructor arg to throw/silent the exception, so that we would not modify the interface.

Question is: which behavior should be the default one?

I accepted the commit you linked as a fix, so we should keep this behavior as default IMO. Then we could have a "$strict" flag to throw exceptions. WDYT?

/ping @sgehrig

sgehrig commented 7 years ago

That's what I'd propose as well. Keep the current (fixed) behavior as default, and allow to switch to a more strict mode. Might be a bit tricky to inject that switch though.

neural-wetware commented 7 years ago

I agree that the API should not be changed. Should we add a $strict = false parameter to getBest()?

willdurand commented 7 years ago

Mmh this would slightly change the interface...

neural-wetware commented 7 years ago

Something like this? #86

willdurand commented 7 years ago

fixed.

willdurand commented 7 years ago

2.2.0 has been released and contains the fix for this issue (cf. #86). Thanks everyone!

willdurand commented 7 years ago

Please see #87