
Hi, I have a subclass of rend.Page. When this page is rendered to HTTP, I want to modify the request object (specifically, I want to set an entity tag, since this resource is quite large when transferred and is being polled every ten minutes). I don't know whether the underlying data has been modified until after locateChild has finished, so I can't modify the headers there, unless I move a lot of functionality into the parent page in the tree. This seems strange from a design point of view. (Why should the parent Page need to know enough about the child to be able to tell if its underlying data source has changed?) 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. -Mary

On May 31, 2004, at 8:50 PM, 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.
Override beforeRender on your Page subclass, or just override renderHTTP directly. beforeRender is a hook for doing exactly these types of things. Nevow streams html to the browser as the page is being rendered, so by the time your render_ method is called, all of the html which logically comes before that has been sent. Thus the headers have already been written. There was also previously a way to indicate that nevow should wait for the entire page render to complete before sending any data, which I may have inadvertently removed in a recent refactor. If it's important to anyone, let me know and I'll look into it. dp

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. -Mary

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

On Mon, May 31, 2004, Donovan Preston wrote:
That's probably an oversight; beforeRender and afterRender should support deferreds.
Filed Issue 49 about this: http://divmod.org/users/roundup.twistd/nevow/issue49
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.
OK, a simple test case (like that attached to Issue 49) shows that this does work, but I'm having trouble with it as part of my codebase. I will hunt for the problem elsewhere for now. -Mary
participants (2)
-
Donovan Preston
-
Mary Gardiner