-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Media Type: Expose more-complete, unstringified parse results #40
base: master
Are you sure you want to change the base?
Conversation
@dougwilson Any thoughts on this? It would really help me out with implementing the negotiation requirements here. Edit: I'd be happy to have the object contain a single |
I'm thinking about it. The main concerns is that once we put it out there, it's hard to ever take it back, so I don't want to rush the decision too much. I don't really like arguments that are just a Boolean, because if you come across the code We probably need to fix the parsing of Otherwise, let me just think on it for a couple days :) If you can, would you be willing to provide an example of what some real-world code would look like utilizing this new option? That would help me a lot as well. |
f7d4b83
to
3fea3cf
Compare
Hey Doug! Sorry it's taken me a while to get back to this :)
Sure, I'll try. I hear you about not wanting to add to the public API prematurely. Unfortunately, though, my actual use case is distressingly complex—a function of trying to comply with a semi-arbitrary (and probably RFC2046-voliating) requirement in the JSON API spec, which is what I'm implementing, while simultaneously trying to provide a sensible content fallback instead of a 406 where possible. So, rather than go into the weeds with my use case, let me offer a related hypothetical example that'll hopefully seem plausible: Imagine a media type (
So, the client sends a request with But, to respond in this way, it needs to be able to inspect the parameters provided with the
Yup. I can look into fixing this if the basic value of the PR makes more sense now. We could also just not expose the parameters after the q-value since, if I remember correctly, they actually have a different semantic meaning, so it probably wouldn't make sense to lump them into the same object anyway.
Updated! |
(P.S. I have not read any of the text yet, but I wanted to let you know don't worry about the 0.8 failure on Travis CI right now) |
Awesome. I was gonna ask about that :) Looks like a package.json thing |
Ok, I have read your response (though I'm about to head to sleep ;) ) and it makes sense to be. It seems to (generally) be yet another example of the issues in #35 and I think it, as a problem, definitely makes sense. |
lib/mediaType.js
Outdated
* @param {string[]} provided The media ranges the server can produce | ||
* for the resource in question. | ||
* @param {Object} options Configuration options | ||
* @param {boolean} options.detailed When `provided` is not defined, such |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
provided
is not defined
Is there a reason why we can't make this work for provided
as well? To me, it seems like just returning these details objects for the matched types, which, if not directly useful, at least would make the API more straight-forward instead of needing to remember that sometimes the option does nothing (and yes, a lot of the current API bothers me, but eventually it can be rewritten ;) ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can make it work without provided
too! I've updated the PR to do that.
3fea3cf
to
ee8b3c3
Compare
@dougwilson Besides the parameter parsing issue, is this ready to merge, now that it works without And about the parsing issue...I actually couldn't reproduce it. When I set Regardless, maybe we shouldn't include the parameters after So, I think the "proper" thing to do would be to output a |
Yes, this is exactly what I said: if we are going to expose the parameters, we cannot start with exposing a bad object from the get-go. The stuff after the first |
Ahh, ok, my mistake. I think your original post had a missing quotation mark, and we've had issues with quotation mark parsing in the past, so I just assumed that was still the problem (rather than the semantic one). Anyway, I've updated the PR now to parse the extensions into a separate object, which I decided to expose after all (unless there's a reason not to?). Let me know what you think :) |
Awesome, will do :) I plan to look it over tomorrow, and a quick glance right now doesn't reveal any real issues :) |
@dougwilson Your ping on expressjs/compression#44 reminded me of this issue too. Let me know if you have a chance to look this over soon :) |
Hi @ethanresnick , I'm sorry I let this sit so long; I'm working on integrating this (and for it to be a uniform option across all methods) currently. I plan to have this (or something similar) released in the next minor. You should be able to drop your fork for the module directly in https://github.com/ethanresnick/json-api/blob/4f710eb0dc8e8a7fcdc2a698c1a00d161cd6ba0f/src/steps/http/content-negotiation/negotiate-content-type.js with the next minor, which is my goal. |
Well, looks like there are still a lot of edge-cases that need to be worked out regarding this interface. For example, I'm wondering about the following cases, if you can provide your input, @ethanresnick :
|
Hey Doug, sorry it's taken me a while on this! To your cases...
Here also I think Because of these issues with parameter matching on the |
It's no problem! And my bad, I guess I was not thinking straight when I wrote that :) Would you mind adding more tests to this PR, specifically tests for negotiator.mediaType with detailed true, which are missing? |
eb73790
to
e2fe4ab
Compare
@dougwilson Done! I've also rebased everything so that it's much easier to follow :) |
@dougwilson Any update on this? |
* Add the facilities for content negotiation, as specified by https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 * The provided options are sorted by quality. When matching, we use semver caret semantics of the provided version to allow backward compatible changes, without the need for clients to constantly update their headers. * We use an unreleased version of the npm `negotiator` package from github. We can switch to the official npm release once jshttp/negotiator#40 is merged. Change-Id: Ie3a7042d78c310ef20eee79cb0a38c7cd40ec3cc
@dougwilson Any chance we can finally get this merged? |
We ran into #35 with an |
For certain advanced negotiation cases that the library can't handle out of the box (e.g. the stuff with parameter semantics that we've discussed elsewhere), it's really useful for the user to be able to get at the parsed media types as
{type, subtype, params, q}
objects.This PR adds an optional third argument,
detailed
that applies to.mediaTypes
only when no types to match are provided. Whendetailed
is true, the user gets back the full list of media types as the objects described above.