Avoid KeyError if no Content-Type header; don't perform unnecessary checks in can_minify_response
When using django-htmlmin in my project, I found that some responses were being returned without the Content-Type header. Even though I was excluding those URLs from being minified using the settings.py EXCLUDE_FROM_MINIFYING option, the structure of the middleware's can_minify_response function did two things that resulted in errors:
- Even after determining via the RegEx check that the URL should be excluded from minification, it continued to perform additional checks that included the error-containing code, and
- The check for the
Content-Typeheader in therequestdictionary would throw aKeyErrorif the header wasn't present.
I've fixed both of those issues, as well as adding an additional test in case request._hit_htmlmin is ever set to False (which it shouldn't be, so why not have a test for it?)
Can we get this merged please?
Any updates on this, please?
I'm affected by this issue too, can you merge it?