[html, ajax] demote_to_html don't crash anymore if force-html-content-type is activated. Closes #712309

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset1b2a05c9b71c
branchstable
phasepublic
hiddenno
parent revision#ffd510fb71da [doc] fix data hooks parent class in Hooks doc.
child revision#e8091b415ad8 [http, windows] fix remove_cookie trying to expire a cookie before the Epoch (closes: #2087998), #6d8eb873256d backport stable
files modified by this revision
web/request.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1320685720 -3600
# Mon Nov 07 18:08:40 2011 +0100
# Branch stable
# Node ID 1b2a05c9b71c4148eb0bf898f812e8c1c6574313
# Parent ffd510fb71dad0e6e84965dec62ed2ea70c2630b
[html, ajax] demote_to_html don't crash anymore if force-html-content-type is activated. Closes #712309

diff --git a/web/request.py b/web/request.py
@@ -793,12 +793,17 @@
1          """helper method to dynamically set request content type to text/html
2 
3          The global doctype and xmldec must also be changed otherwise the browser
4          will display '<[' at the beginning of the page
5          """
6 -        self.set_content_type('text/html')
7 -        self.main_stream.set_doctype(TRANSITIONAL_DOCTYPE_NOEXT)
8 +        if not self.vreg.config['force-html-content-type']:
9 +            if not hasattr(self, 'main_stream'):
10 +                raise Exception("Can't demote to html from an ajax context. You "
11 +                                "should change force-html-content-type to yes "
12 +                                "in the instance configuration file.")
13 +            self.set_content_type('text/html')
14 +            self.main_stream.set_doctype(TRANSITIONAL_DOCTYPE_NOEXT)
15 
16      def set_doctype(self, doctype, reset_xmldecl=True):
17          """helper method to dynamically change page doctype
18 
19          :param doctype: the new doctype, e.g. '<!DOCTYPE html>'