django-html-validator icon indicating copy to clipboard operation
django-html-validator copied to clipboard

KeyError: 'content-type' when response['Content-Type'] is not set

Open int-ua opened this issue 5 years ago • 6 comments

AFAIU response['Content-Type'].startswith('text/html') in middleware.py should be replaced with 'text/html' in response.get('Content-Type', '').

int-ua avatar Aug 20 '18 15:08 int-ua

Really? What kind of Content-Type do you have that doesn't start with text/html?

peterbe avatar Aug 20 '18 15:08 peterbe

It's just None somehow. I'm using ListAPIView and a CSV renderer from rest_framework_csv.

int-ua avatar Aug 20 '18 16:08 int-ua

Oh I see. Perhaps something like this instead:

if response.get('Content-Type', '').startswith('text/html'):

What do you think?

peterbe avatar Aug 20 '18 16:08 peterbe

Looks like it would also work, yes

int-ua avatar Aug 20 '18 16:08 int-ua

Cool. Make a PR with a unit test and I'll merge it.

peterbe avatar Aug 20 '18 16:08 peterbe

Don't forget to comment about why sometimes the response doesn't have a Content-Type header.

peterbe avatar Aug 20 '18 16:08 peterbe