Well, I have middleware class which is required to determine content-type of rendered page and if it is 'txt/html', then do some action. I've started just from seeing what content-types do I have on page and here is first problem I faced:
class StatsMiddleware(object):
def process_view(self, request, view_func, view_args, view_kwargs):
response = view_func(request, *view_args, **view_kwargs)
print response['Content-Type']
Executing this, I get few messages about content-types of page elements, like text/html, application/javascript and also
tons of errors like key error: content-type and after that - broken pipe
So I assume that not all elements of page have such header Content-Type and my question is following:
Is there some general Content-Type that says 'That page is text/html' or there are a lot of content-types on page ?
And also if this is a proper way to deterimne content-type of page like this:
if response['Content-Type'] == 'text/html':
pass
if response.get('Content-Type', '').startswith('text/html'):
pass