jshttp / negotiator

An HTTP content negotiator for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Accept-Language` in different casing

caridy opened this issue · comments

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

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

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 :)

awesome, thanks you guys!