[Twisted-web] Setting the twcgi header?
dp at ulaluma.com
Mon Jul 12 08:15:27 MDT 2004
On Jul 12, 2004, at 4:12 AM, Sergio Trejo wrote:
> I'm quite new to Twisted and Twisted.web but have been playing around
> with it the past several days and enjoying my new learning experience.
> Please someone correct me if I'm wrong, but can't you just write out
> the Content-Type, etc. to a Resource instance by overriding its
> render_GET() method (e.g., request.write())?
> from twisted.web.resource import Resource
> class myResource(Resource):
> isLeaf = True
> def render_GET(self, request):
> # see API documentation for:
> # write(self, data)
> # Write some data as a result of an HTTP request.
request.write is for writing the body of the request, not the headers.
To affect the headers, see below.
>> class PythonCGI(twcgi.FilteredScript):
>> filter = '/usr/local/bin/python'
>> I wish to set the following header for my PythonCGI:
>> print "Content-type: application/x-shockwave-flash\n\n"
>> But, instead the script renders:
>> Connection: close
>> Content-type: text/html
>> Server: TwistedWeb/1.3.0rc1
>> How do I change the header?
Override render_GET, and then call setHeader('content-type',
'application/x-shockwave-flash'). There may also be some sort of
attribute you can set which will cause FilteredScript to do this for
you, I'm not sure. Examine the source code.
More information about the Twisted-web