Comments (5)
Hi everyone, sorry I have been away with other things.
For Accept-Language header, this module specifically only implements the algo linked to from the HTTP RFC (https://tools.ietf.org/html/rfc7231#section-5.3.5). To quote from that section of RFC 7231:
For matching, Section 3 of [RFC4647] defines several matching
schemes. Implementations can offer the most appropriate matching
scheme for their requirements. The "Basic Filtering" scheme
([RFC4647], Section 3.3.1) is identical to the matching scheme that
was previously defined for HTTP in Section 14.4 of [RFC2616].
The "Basic Filtering" algo is what this module currently implements for Accept-Language header, as it is the algo web servers have always traditionally implemented for selecting a language from a set list for HTTP applications. The full test of this algo is in RFC 4647 here: https://tools.ietf.org/html/rfc4647#section-3.3.1
How the basic filter algo works is also illustrated in a previous comment I made here #46 (comment) which applies to the original post as well.
I'm not really familiar with the ago in RFC 4647 that would produce the expected results in the original post. @tangye1234 would you be able to link directly to the section in RFC 4647 that defines the algo you're expected and than use your example to walk though it? I'm 100% open to adding additional defined algos to the list such that you can choose which one to use when matching language tags 👍 the PR above was changing the existing standards-defined algo which is why it was marked as wontfix
, though adding additional algos from the RFC as options to alter behavior is perfectly acceptable.
I hope this makes sense.
from negotiator.
How coincidental, I just ran into this issue as well.
var Negotiator = require('negotiator');
var req = { headers: { 'accept-language': 'en-CA,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,fr;q=0.6,pt;q=0.5,th;q=0.4' } }
var negotiator = new Negotiator(req);
negotiator.languages(['en-GB', 'en-US', 'en-x-pirate']);
[ 'en-x-pirate', 'en-GB', 'en-US' ] // output
In my scenario the en
should match en-GB
first at priority of 0.8. en
substring match with en-x-pirate
should be considered only after all exact matches have been exhausted.
from negotiator.
@tangye1234 #46 provides a bit more context, and @dougwilson has shown that this module adheres to RFC 4647, so this unfortunately is a wontfix
from negotiator.
@julianlam, I think @dougwilson is trying to explain the case Apache mod_negotiation and jshttp/negotiator behave the same, but that is not what rfc4647 describes, the RFC only describes that in this case language cannot be selected out, but only be filtered with a fallback list, while users would decide for their own.
Maybe he is right because the negotiator cannot make decisions for the user, unless user send another accept-language list: en-GB, en;q=0.9
that follows the the suggestion from RFC:
the user SHOULD specify the most specific (largest number of subtags) range
first and then supply shorter prefixes later in the list
from negotiator.
Assuming we want to define additional algos to the call to negotiator, how would this be achieved, as a second argument for .languages
?
from negotiator.
Related Issues (20)
- Fails to parse quoted parameters HOT 10
- Parameter names should be case insensitive HOT 4
- Parameter value case-sensitivity is media-type specific HOT 5
- Is there a reason this library doesn't support charset as a parameter on Accept header? HOT 8
- `Accept: *` results in no media types. HOT 6
- language function does not return expected language HOT 1
- Negotiator behavior on duplicate accept content-types HOT 1
- es6 support HOT 2
- Caching the availableMediaTypes HOT 1
- Functionnal API HOT 2
- [Bug] parseCharset(str, i) changes value of i HOT 4
- [Question] More preferredCharset() stuff HOT 2
- [Question] parseMediaType(), and parameters after q-value HOT 4
- Ship version 1 and adopt semver? HOT 9
- 0.6.3 Release HOT 8
- Inconsistent mediaType/s handling HOT 1
- Returning */* no matter what I set as header. HOT 4
- language function does not return the expected language in nextjs middleware HOT 3
- Language negotiator returns first item of availableLanguages array no matter what HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from negotiator.