[Zope] Content-type for a method or script

Oliver Bleutgen myzope@gmx.net
Mon, 29 Oct 2001 17:15:55 +0100

Trevor Toenjes wrote:

>><dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')">
>><dtml-var "mytestgif.data">
> Thanks.  Yes, that works alone to serve the image.
> But when I include something like this below, it doesnt work.  I dont know
> why...
> <dtml-if expr="UID == 'myid'>
>     <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')">
>     <dtml-var expr="mytestgif.data">
> <dtml-else>
>     <img src="http://anotherdomain/bar.jpg">
> </dtml-if>

Because you now serve several whitespaces (i.e. spaces, newline, 
carriage-returns whatever) together with the imagedata.
To illustrate
<dtml-if expr="UID == 'myid'>\n
____<dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')">\n
____<dtml-var expr="mytestgif.data">\n
____<img src="http://anotherdomain/bar.jpg">\n

I have replaced spaces with _ and newline with \n.
So if UID == 'myid' the browser gets:

____Content-Type: image/gif\n

You see, that is wrong, it should get:

Content-Type: image/gif\n

This is ugly to get right in a dtml-method, you have to put it all in
one line, without _any_ whitespace.
Can't you just do (or similar, this is untested) the follwing?

<dtml-if expr="UID == 'myid'>
     <dtml-return "RESPONSE.redirect('http://hostname/mytestgif')">
     <dtml-return "RESPONSE.redirect('http://anotherdomain/bar.jpg')">