jshttp / negotiator

An HTTP content negotiator for Node.js
MIT License
309 stars 33 forks source link

`Accept-Language` in different casing #27

Closed caridy closed 9 years ago

caridy commented 9 years ago

We have noticed that some browsers will send the Accept-Language header all in lower case (e.g.: fr-fr), some others will send it as fr-FR. This put a borden on the user to deal with these differences when it could be done at the lower level. Here is a repro case using npm REPL:

var n = require('negotiator/lib/language');
undefined
> n('en-GB', ['en-US', 'en-GB', 'fr-FR'])
[ 'en-GB' ]
> n('en-US', ['en-US', 'en-GB', 'fr-FR'])
[ 'en-US' ]
> n('en-us', ['en-US', 'en-GB', 'fr-FR'])
[]  // FAILS
> n('en-gb', ['en-US', 'en-GB', 'fr-FR'])
[]  // FAILS

what is the recommendation to solve this problem? can this be covered by negotiator/lib/language directly?

/cc @ericf

federomero commented 9 years ago

I think negotiator should handle this. I can write a fix for this over the weekend.

dougwilson commented 9 years ago

I checked and verified that RFC 4647 (via RFC 7231) does indeed say comparisons are to me made case-insensitive, just as a point of reference :)

caridy commented 9 years ago

awesome, thanks you guys!