django-htmlmin icon indicating copy to clipboard operation
django-htmlmin copied to clipboard

Avoid KeyError if no Content-Type header; don't perform unnecessary checks in can_minify_response

Open jdotjdot opened this issue 10 years ago • 3 comments

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:

  1. 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
  2. The check for the Content-Type header in the request dictionary would throw a KeyError if 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?)

jdotjdot avatar Jun 22 '15 01:06 jdotjdot

Can we get this merged please?

vinitkumar avatar Oct 09 '15 09:10 vinitkumar

Any updates on this, please?

vinitkumar avatar Feb 11 '16 10:02 vinitkumar

I'm affected by this issue too, can you merge it?

diegoponciano avatar Mar 01 '16 18:03 diegoponciano