[ZPT] including text/xml templates inside a text/html template changes Content-Type

Troy Farrell troy@entheossoft.com
Wed, 29 Jan 2003 11:12:36 -0600


The XML-thingy I am inserting is a page template called complex_dv_doc. 
  It's content type is text/xml.  I agree with your hypothesis about it 
setting the Content-Type when it's rendered before insertion.

Hmmmm. I smell a bug.

I tested my theory by doing this:

1) changed the content type of the last outside template called from 
text/xml to application/whackadoo.

2) GET /dailyverse/index_html HTTP/1.0

What do I find?

Content-Type: application/whackadoo

Erg.  Looking at the zope 2.6.0b2 changelog:

       - Zope Page Templates set a 'content-type' header even if
         the result of their execution was not rendered to the browser.
         We now check to make sure a content-type header is not
         already set before allowing a page template to set its own.

I'll test this issue on Zope 2.6.0 (currently on 2.5.1) and see if it is 
still a problem.

Thanks.
Troy

Clemens Robbenhaar wrote:
> Hi Troy,
> 
>  > I have a pt (index_html) that is text/html.  Inside this template, I 
>  > have something like this, twice:
>  > 
>  > <pre tal:content="here/complex_dv_doc"></pre>
>  > 
>  > This basically includes another template from the same folder.  In this 
>  > case, complex_dv_doc is a text/xml document which is html quoted 
>  > automatically (because I didn't use structure).  As those of you using 
>  > IE will notice, this results in the Apache <- PCGI <- Zope monster 
>  > returning my html document as Content-Type: text/xml.  Since I use 
>  > Mozilla/Linux all the time, I never noticed until a user told me my site 
>  > had problems :(
>  > 
>  > My question is this:  Is that normal?  If so, what should I do to fix it?
> 
>  I do not know of what type the XML-thingy is which You inserting there.
> Is this a "File" object?
>  
>  Anyway, it seems this object sets the 'Content-Type' Header of the
> response to 'text/xml' when rendering itself, even if it is rendered
> via another object. 
> 
>  A hackish way is to change the header back (untested, sorry):
> 
> <pre tal:content="here/complex_dv_doc"></pre>
> <tal:hack define="dummy python:request.RESPONSE.setHeader('Content-Type','text/html')" />
> 
>  A less hackish way would be to call some method of the XML object,
> which does return the contents wothout setting the 'Content-Type'
> header. If such a method exists depends on the object You querying ...
> 
> Hope this helps,
> Clemens