Raise an exception when the header cannot be parsed#8
Conversation
Raise an exception when the header cannot be parsed
|
Thanks. Merged. |
|
Great, thank you @dbtsai! Could you release an updated pypi package? |
|
Let me do it durning the weekend. Thanks. |
|
@wojcikstefan The build is broken with your patch, https://travis-ci.org/dbtsai/python-mimeparse/builds/105085056 |
|
Yup, will do. Thanks for pointing that out! |
|
This was a backwards-incompatible change and should have been released under a new major version. I'm guessing there are currently a lot of broken builds out there right now. |
|
@wojcikstefan Can you address the concerns raised by @mattbriancon? Thanks. |
|
@mattbriancon could you elaborate? Providing an invalid mime type format already resulted in an exception here (though it indeed was a different exception type - |
|
It's the change in the exception type. https://github.com/django-tastypie/django-tastypie/blob/master/tastypie/utils/mime.py#L37-L40 |
|
Tracking the issue here: django-tastypie/django-tastypie#1429 |
|
@mattbriancon let me clone |
|
@mattbriancon @dbtsai I just opened #13 - it should fix the issue. |
Also refactors unit tests so that they produce an expected output upon success and failure.
The main rationale behind
MimeTypeParseExceptionis that if somebody sends a request as follows:requests.get(url, headers={ 'Accept': 'text' })... the server should respond with a 400 saying that the header is not formatted properly. Right now, we'd have to do the validation outside of the library (introducing somewhat duplicate code) or we'd have to catch a
ValueError(because(type, subtype) = full_type.split('/')would raiseValueError: need more than 1 value to unpack), which is too generic. Merging this PR will help me submit a similar PR to https://github.com/martinblech/mimerender utilizing the new exception type and returning a valid response.