setting the content-type of myghty output

setting the content-type of myghty output

Myghty’s documentation is pretty good, ‘cept for the part that tells you how to set the Content-Type header. Well, it tells you where in your code to set headers, just not how you go about doing that…

The r object, the request object, is the place that spits out the HTTP headers, including the content type, and it defaults to text/html; you can see this in http/HTTPHandler.py and http/CGIHandler.py.

So, in your <%python scope="init"> section, just set

r.content_type = "text/xml"

or whatever you like.

Come to think of it, though, I don’t think there’s a way (at least, based on my brief glance at the code to find out about content_type) to set arbitrary HTTP headers. (If the maintainer of Myghty stumbles across this post, please make the request object a dictionary-like object, a-la Python’s email.Message, thanks :-)