[Twisted-web] Set request headers in rend.Page

Donovan Preston dp at ulaluma.com
Mon May 31 19:18:48 MDT 2004


On May 31, 2004, at 9:03 PM, Mary Gardiner wrote:

> On Tue, Jun 01, 2004, Mary Gardiner wrote:
>> Is there some point where I can add new headers to the request in a
>> Page itself? I haven't tested thoroughly, but it seems to me that the
>> HTTP headers have already been transmitted by the time render_ and
>> data_ methods are called.
>
> Looking at the implementation of rend.Page.renderHTTP makes me suspect
> that the way to do this is by making a beforeRender(self, request)
> method. Is this right?
>
> And if so, beforeRender looks like it's meant to be synchronous, and
> unfortunately my "check for new data" method needs to wait on a 
> Deferred
> to be called back.

That's probably an oversight; beforeRender and afterRender should 
support deferreds. Until that works though, you should override 
renderHTTP and return a deferred. Do this:

def renderHTTP(self, request):
     d = doSomethingDeferred()
     return d.addCallback(self.myCallback, request)

def myCallback(self, result, request):
	# Do whatever
	return rend.Page.renderHTTP(self, request)

rend.Page.renderHTTP returns a deferred which fires when the page is 
done rendering.

dp




More information about the Twisted-web mailing list