willdurand / Negotiation

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

InvalidMediaType exception #71

Closed oscarotero closed 8 years ago

oscarotero commented 8 years ago

Hi. From the google spiders, I get the following Accept header: text/html, image/gif, image/jpeg, *; q=0.2, */*; q=0.2 And this generate the following exception:

Negotiation\\Exception\\InvalidMediaType(code: 0):  at /vendor/willdurand/negotiation/src/Negotiation/Accept.php:20)

I think the problem is the first * that should be */*. Maybe this library should treat * as equivalent to */*?

willdurand commented 8 years ago

Interesting. I have to look at the RFC again, because I don't remember anything about * only.

luxifer commented 8 years ago

I had the problem earlier. I had a client using my API with a java lib which sends Accept: *. I also looked in the RFC and it's not.

willdurand commented 8 years ago

@luxifer so it is invalid anyway? If so, question would be: should we accept such an incorrect behavior?

luxifer commented 8 years ago

Yes it is invalid, but I don't think the lib should be so strict because the HTTP RFC is not 100% valid anywhere. There are some edge cases like this one. But what to do? Force the user to encapsulate the statement in a try/catch? Do not throw an exception in that case?

willdurand commented 8 years ago

Maybe supporting this would be ok... @oscarotero wanna work on a patch?

oscarotero commented 8 years ago

Yep, no problem. As soon as I have some time available, I will.

oscarotero commented 8 years ago

Here's the PR: #73