-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Accept header parsing #2171
Comments
While it is nice to support standards, I believe there is little practical use for full parsing of this header. Pretty much the only thing supplying more than one type is the browser requesting pages, images, scripts etc. (each with their own accepted types), and even then the lists come already in order of precedence. And that precedence might not make much sense in regards to what formats you actually want to use (e.g. I suppose that Not saying it shouldn't be done like you proposed, just raising points. Needs more thinking and practical use cases. |
Agreed. I think the practical use case (as you alluded to in #2162, and what was the original inspiration for this RFC) would be to allow Sanic to make some "smart" decisions. Of course this could be extendable, and having wildcard support might be ideal. However, I am not sure that we need to be overly concerned with that in the core project just yet. I would be content to simply order them appropriately and let whatever implementation that plans to use the property determine how to handle the |
The
Accept
header in RFC 7231 § 5.3.2 has a very structured format for specifying media types that the client can accept, and also would prefer to accept.Source
#2162 adds some context based error formatting based upon the initial #1937. Where both of those PRs are lacking is the ability to confirm that the media being sent is warranted and acceptable.
The proposal is to add a new accessor:
Request.accept
that provides a simplified list of acceptable types in preference order. Where there is a tie for equal precedence, Sanic should prefer the first to be listed in the raw headers.This change will allow for the error response to make sure that it is sending an appropriate format, and also provides the developer an easy way to select one of multiple formats for responding. The last potential benefit is that Sanic could offer a "strict mode" (defaul=False) that would raise an error if it attempts to respond with a type that is not acceptable.
The text was updated successfully, but these errors were encountered: