-
Notifications
You must be signed in to change notification settings - Fork 11
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
request: add support for parsing and matching suffixes #50
Comments
matching by (group and (subtype or suffix)) to be exact |
Hi, is your objective to add a function that given the result of I guess we could add it. Changing the result of |
I was thinking of: >>> parse_mime_type('application/vnd.oai.openapi+json', suffix=True)
('application', 'json', {})
>>> parse_mime_type('application/json', suffix=True)
('application', 'json', {}) This way keeps compatibility and Also, is the part between '/' and '+' useful for anything? I thought you either work with full media type |
If we introduce a new flag we can also return a 4-tuple when it's true, since it's a new feature. Or have the second item of the 3-tuple be a 2-tuple (or a named tuple) instead of a string. This would work better if the flag is called @vytas7 what your opinion on this? |
To be honest, I'm not a big fan of adding this to the current interface, because it is not really in the spirit of RFC 9110, Section 12 (Content Negotiation). The RFC does not really define a way to provide wildcards ( Although I do understand the value proposition in some scenarios, could you tell more about your use case @rafalkrupinski? Could we maybe somehow extend these matching functions by adding an optional regex parameter to match things? Dunno how exactly it could look like. |
httpx.Response.json() can deserialize the body if it's JSON. The current implementation doesn't check content-type header, but imagine similar scenario def python(self: 'Request')->dict|list|str:
deserializers = {
'application/json': deserialize_json,
'application/yaml': deserialize_yaml,
...
}
match = mimeparse.best_match(deserializers.keys(), self.headers['content-type'])
return deserializers[match](self.body) In the above example edit: I've hopefully clarified my explanation with a piece of code. So that's the client side, lets look at the server side. Suppose the server can handle |
To be fair, Falcon itself has a hack in one place to support Right now, Falcon's media handling doesn't support this scenario either for request media, but maybe we should have an option too 🤔 (Falcon's media is very similar to your serializers and deserializers, just on the server side.) |
@vytas7 so how do you want to continue? |
Just to be honest, myself, I don't have much incentive to introduce any new major features to this library, but we can accept your suggestions or contributions :) The first step, I think, is to agree on a good API design. Your proposal, as I understand, is to have an option to How would that be propagated from the matching functions (are you using |
Since the times of XML media often have a suffix, for example
application/vnd.oai.openapi+json
. This conveys separate information on syntax and semantics.Ability to match by group and suffix (in the example:
application
,json
) would let applications to communicate the exact media type, and libraries to process such content in a generic way.The text was updated successfully, but these errors were encountered: