Comments (5)
Hi @marcinn , sorry for the delay. Yup, that quote is spot on and I think this package should respect that rule.
I think the change I proposed in #26 is the right step forward. It doesn't break any of the previously existing unit tests and - prior to the change - the behavior for using qvalue server-side was simply undefined. Now, we're defining it according to the RFC.
from python-mimeparse.
Thanks @wojcikstefan! Sorry for late response. I missed your reply. Best regards!
from python-mimeparse.
Hi @marcinn ! Typically the quality is specified on the types the client accepts and not the server's acceptable types. I haven't seen something like this before. Can you point me to some resource (e.g. a section in the RFC) where this behavior is described?
I preemptively implemented #26 in case we agree to do it in the way you described.
from python-mimeparse.
I've just saw that RFC7231 section 5.3.1 contains a phrase which describes what I'm doing:
This weight is referred to as a "quality value" (or "qvalue") because the same parameter name is often used within server configurations to assign a weight to the relative quality of the various representations that can be selected for a resource.
I'm creating a server which should serve a best matching and preferred representation. When client accepts anything (*/*
), the server should respond with most-common/preferred mediatype. My implementation is based on mimeparse.best_match()
. I'm passing acceptable media types and the client's header as arguments, but the function fails in that case.
I've declared a qvalue for a server's accetable types in a similar way how @Produces
annotation work (please look at this), but using q
instead of qs
believing that mimeparse
will do such matching automatically. But it didn't.
I realize that mimeparse.best_match()
is written mostly for client's content matching and I can rewrite media type negotiation without using mimeparse
, of course, but I'm also wondering about implementing it inside exisitng package - it is designed to do such things, I think. That's why I'm asking.
Looking at your patch I can just say that "the fix" is quite simple, but it is related to quality_and_fitness_parsed()
. So it affects not only best_match()
, but also quality_parsed()
.
Your patch works for me, but it may break compatibility for others (in cases where clients are not sending Accept
header or asking server for anything). Is this a good idea? I don't know...
from python-mimeparse.
v1.6.0 released
from python-mimeparse.
Related Issues (14)
- parse_media_range overrides quality values of 0 HOT 1
- Broken download_url link in setup.py HOT 3
- ValueError in 1.3 python version HOT 4
- mimeparse vs python-mimeparse HOT 16
- Handle */* as one of many parts gracefully HOT 1
- Wrong ordering of candidates HOT 1
- Drop python 2 HOT 2
- Modernize code HOT 4
- Migrate ci to github action
- No python installation found in registry error on install
- Consider using `lru_cache`
- Modernize setup
- Benchmark and optimize code HOT 1
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 python-mimeparse.