Comments (5)
I looked at this a little, but it's hard to wrap my head around the use of these params. The RFC is pretty vague about exactly how they should be used and matched against.
Searching around for content negotiation doesn't yield much information about them either. The best reference I could find are these apache docs which seem to indicate that when apache does content negotiation it only even bothers to look for a level
param? The RFC says there can be multiple media range params, but it too only uses level
in the examples.
I'm not really sure what should happen when there are multiple params, or whether q values should take precedence over specificity of the params?
from negotiator.
Thank you @therigu and @jdeerhake.
First of all, I think this discussion is pretty theoretic because I believe these params have no real practical use (please correct me if I'm wrong).
That being said, I agree with @therigu that negotiator is not handling this case correctly. I'm not 100% convinced how it handle it though. Consider the following cases:
Let's say we have Accept: text/html;attribute=value
.
Is text/html
an acceptable media type? What about text/html;attribute=other
?
I think strictly speaking, it should probably reject both. But maybe it's preferable to accept the first one, or maybe both. I can't really find anything on the RFC that indicates which is the right solution.
What do you guys think?
Regarding specificity vs. q value, I think specificity takes precedence.
from negotiator.
I tend to think that as long as they don't have the same attribute with conflicting values, then it's a match. The RFC makes it clear that if we had Accept: text/html
then text/html;level=3
would be an acceptable response, so it makes sense to me that the reverse would be true.
I started to refactor it to function like that and kinda ended up rewriting the whole file. https://github.com/jdeerhake/negotiator/commit/a1e142bd81d3d91782664e0ca9131f63f8d99939
from negotiator.
I don't think the reverse necessary holds. Saying Accept: text/html
is like saying I want a car and Accept: text/html;level=3
is like saying I want a red car. It makes sense to me that if you ask for a car, a red car would be an acceptable response, but not the other way around.
from negotiator.
I ended up handling this strictly since I think that most consistent with how content negotiation works in general.
This commit 334105a takes care of that.
Thanks
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
- Accept-Language comparing standard currently differs between `getLanguagePriority` and `compareSpecs` HOT 5
- [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.