[mod_python] How do you make a subrequest?

Nick nick at dd.revealed.net
Thu Jan 20 15:03:07 EST 2005

You could just use urllib(2) to make requests back to the server to get the 
output from the page you want.  Not pretty, but it'll get the job done.


Nicolas Lehuen wrote:
> On Thu, 20 Jan 2005 11:07:19 -0800, Scott Sanders <sanders at apache.org> wrote:
>>I don't think that is what req.internal_redirect() does.  I want the
>>main request and the sub request to participate in the output, for
>>example, a server side include:
>>Main request puts out the html header information, then calls a sub
>>request to put out the menu html, then the main request takes over
>>again and outputs the rest of the page, etc.
>>I really need the sub request to return it content to me, and not to
>>the user.  With internal_redirect(), the original request loses control
>>over the process, when I would like it to participate again.
> I wonder if this would be best solved by a mod_python level method
> such as req.include_request or by a higher-level page composition
> framework.
> In the Java world, they solved it by a Portlet framework built above
> the Servlet framework, but they may have chosen the high-level route
> because it was too late to do thorough changes to the servlet API.
> There is a problem if you want to compose pages from "patches" (in the
> sense that your page becomes a "patchwork") built by different
> handlers (I assume that's what you mean by "subrequest"). Low-level
> handlers are supposed to respond to an HTTP request and build an HTTP
> message in response.
> Typically, a handler will write on the request output stream. That's
> not really a problem if you call the subrequest handlers at the
> precise place you want them inserted into the patchwork, but there
> still remains a problem with HTTP headers. So you could build a mock
> request object, ask mod_python for the proper handler for a given
> internal URI, run it with the mock request object and decide what you
> do with its output HTTP headers and the generated content (typically,
> discard the HTTP headers other than Set-Cookie and output the content
> on the connection).
> It could work, but it feels a bit like a hack, and I think that's why
> the Java people opted for an independent content composition framework
> (the Portlet API).
> On the other hand, you can already do what you want by yourself,
> without touching any part of mod_python, just by putting your various
> patches in shared modules, importing those modules in the various
> published modules or PSP pages, call your patches and expect them to
> return a string to be included in your current document. What's the
> problem with this approach ?
> Regards,
> Nicolas
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list