[ZPT] response.setHeader() best practice

Toby Dickenson tdickenson@geminidataloggers.com
Tue, 09 Apr 2002 16:35:37 +0100


On Tue, 9 Apr 2002 10:41:38 EST5EDT, Alan Kennedy <zpt@xhaus.com>
wrote:

>.... thrash out now

Agreed.

>[Toby wrote]
>> It doesnt *have* to vary; you could use an encoding such
>> as UTF-8 which can represent the whole unicode range.
>
>Agreed. But using Unicode is not an optimal solution because
>
>1. UTF-8 is culturally biased towards western languages
>2. UTF-16 is wasteful of bandwidth if you're only using <=20
>200 characters out of the 64K range (unless you're using=20
>compression, but that's another issue)=20

Sure. In many cases using a regional encoding is appropriate too.

My take on the situation is a little different to yours; I recommend
the use of UTF-8 unless there is a 'cultural bias' towards a specific
regional encoding. It avoids a number of sticky problems, with only a
moderate size cost.

>> The right thing to do in Zope 2.6 will be:
>>=20
>> 1.Ensure the published method returns a unicode object
>> 2.Set a response header Content-Type:=20
>text/html;charset=3DXXXXX
>>=20
>> ZPublisher will automatically convert the unicode string
>> into an 8-bit format=20
>
>That's clever, (and potentially resource-costly?)

My first implementation was a few percent slower than the 'all in
latin-1' solution, and it has been optimised since then.

>> using the specified character encoding.
>
>Ah, we've gone full-circle. Where is that character=20
>encoding specified?

I have no idea on the best way for ZPT to set the Content-Type
header...=20



Toby Dickenson
tdickenson@geminidataloggers.com