-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matching parameters #30
Comments
Forgot to add that I'd also like to support an optional suffix, making a total of |
So when doing negotiation, you are providing an ordered list. You should be providing a list like switch (req.accepts('application/vnd.foo.bar; v=2', 'application/vnd.foo.bar; v=1', 'application/vnd.foo.bar')) {
} Charset negotiation is not part of the Would you be able to share a more real example of what you're trying to do? I want to make sure it actually fits into how negotiation is specified in RFC 7231 and I'd be happy to work out a solution, but I just need a more real example to work with. |
Hey, thanks for the prompt reply. There is indeed A few valid examples I'd like to match:
A few invalid examples:
Having enumerated all of these examples I'm thinking it might be easier to filter the given |
Please, do not negotiate charset within the As far as iteration yourself, have you tried to just use this module directly (or the var accepts = require('accepts')
var accept = accepts(req) // has header Accept: application/vnd.foo.bar; v=1; q=0.5, application/vnd.foo.bar; v=1
console.log(accept.types()) // provides the types in q-order I mean, you can just use a switch statement. Your want to violate RFC 7231 and include the |
Charset seems to be a hot topic. RFC 2046 on the other hand presents Perhaps
My allowance for optional values is related to convenience and beauty. When doing requests manually for testing purposes, I can't be bothered to type that much. I'm thinking of actually parsing the types once per request and sorting/filtering manually. With all of those |
So, RFC 2046 has nothing to do with HTTP content negotiation. It talks about the use of the content-type field in an email that actually has a body. Even in HTTP the stuff you provide to the Basically trying to bundle charset negotiation within the If you would like, feel free to email me and I can setup an hour or so conversation about how HTTP content negotiation functions and what the best practices are, etc. Also remember that as soon as you start changing the way content negotiation is done, various clients that have negotiation built in to them won't be able to successfully negotiate, for example, the charset with your API, as they have no idea you want them to add it as a parameter in the |
Hey again. Thanks for the thorough response. I've spent some time with those respective RFCs as well and have come to the conclusion that both I've simplified my original requirements slightly, but still was unable to do what I needed with Negotiator or its underlying MediaTyper library. So I did what every self respective OSSian would do and created what I believe to be a better type parsing library: MediumType.js. As I remember you were using the MediaTyper module underneath, you might want to look at MediumType. It behaves more correctly and is far easier to optimize. For example, it does not parse a comma separated array of types with parameters with commas incorrectly (although I think that was more Negotiator's shortcoming than MediaTyper's). You can also parse types once and then re-use those for matching, thereby improving performance. It's also a decent value type and not merely a plain object. Give it a try. Thanks for the call proposal. I think I'll actually take you up on that offer. Always interesting to chat with people who care. |
This module doesn't actually have any dependencies, least on one called |
Ah, you're right. I must have this confused with |
No problem, though that has a dependency on
Yep, I agree :) But these modules only operate directly on |
Yeah, remembered that at the last moment. Updated the comment shortly after. :)
Fortunately, not exactly. When Negotiator is used as middleware, it does have state. Or can have. That'd be a great time to preparse types. Feel free to use MediumType as a dep for proper splitting. And parsing while you're at it. ;-) I think Negotiator also handles quoted parameters wrong. ^_^ |
I'll check it out, for sure. Can you also explain how |
Sorry, I don't recall After having tried all of those media type libraries on NPM and having spent quite some of time reviewing them, I was just frustrated. I didn't see any that in my opinion had quality in them. Just some code thrown against the wall. I might've used It probably also ignored inherited properties in parameters, which is my pet peeve fight against accidental complexity. :-P I'll have none of that sometime-works/sometimes-doesn't handling of inherited properties in my code. ;) |
Ah. You mean, it just doesn't support the types of values that are allowed in the
This is one of the biggest problems in Node.js land, and was the whole reason
Hm, what does that mean? You're talking about the |
Sorry, "type" was an overloaded term there. By type class I meant an instance of a class (or child of a prototype in JavaScript parlance) that acts as a native type. One you can do |
oooo, lol. So you means that it's because it returns a plain object instead of something that's more useful and has methods, etc. |
Yeah.
Yep .That particular one wasn't an objective criticism. Type classes are just something I find convenient to work with. Primarily |
Oh, yeah. That's why I had to reimplement that bit as well. That parser would have to understand the syntax of a media type to properly handle embedded commas. ^_^ MediumType's does. 😎 |
Hey,
I'm trying to use the Accepts module via Express (
req.accepts
) and thereby Negotiator to match some media types. They're in the form ofapplication/vnd.foo.bar; v=1
.I'd like to cover the use cases of where the
v
is missing (to default to the latest version) and where the optionalcharset
parameter is given. I do see some wildcard matching inlib/mediaType.js
, but that only works from the requester side (HTTPAccept
header in my case).How would one do this? If it's necessary to enumerate all permutations of parameters, that sounds like an awfully lot of parsing work to be done for every request.
Thanks!
The text was updated successfully, but these errors were encountered: