On Tue, Dec 8, 2009 at 9:04 AM, Jonathan Vanasco <[email protected]> wrote:
> First, thanks all.
>
> Subrequests in Apache are weird. IIRC, they appear to be a new request
> - but something in mod_perl's request context object will note that it
> is a subrequest, and provide a facility to access the 'top level'
> context object information.  this is in line with what Shailesh
> stated.
>
> Mike-
>  you bring up "return self.othermethod()" as an alternative.
>  do you think this would work :
>      return OtherController().othermethod()

I'd think so because that's essentially what Pylons does.  But I
vaguely remember that somebody might have had problems with it a year
or two ago.  I'd say try it and see if it does what you expect. You'd
have to supply any arguments the method expects, of course.  Normally
Pylons does this by introspecting the argument names and supplying
them from the routing variables.

Wichert Akkerman wrote:
> I'm quite sure Paste has some API that allows you to do subrequests from 
> Pylons.

Ben might know a way, but I don't.  Although some ideas are below.

> You could look at how middleware such as URLMapper or Deliverance handle that.

Middleware are in a different situation.  They have the application
(the next middleware) and call it in the WSGI manner.  So they can
call it on their own URLs instead of the original URL.

But that brings up something that occurred to me this morning.  If you
have the PylonsApp instance, you can call it as a WSGI application
too.    But I don't know where you'd get the pylonsapp from because I
don't see it in 'config' or 'request.environ'.  You could
reinstantiate it by calling make_app() with full_stack=False, and then
call it.  I'm not sure if the Pylons globals would be overwritten, but
as long as you don't use them for anything else after calling the app,
it wouldn't matter.

So the action would look something like this:

# Untested
def subrequesting_action(self, environ, start_response):
    sub_environ = environ.copy()
    sub_environ["PATH_INFO"] = "/other_url"
    sub_environ["REQUEST_METHOD"] = "GET"
    sub_environ["QUERY_STRING"] = ""
    sub_environ["wsgi.input"] = StringIO("", "r")
    return pylonsapp(sub_environ, start_response)

Or using WebOb:

# Untested
def subrequesting_action(self):
    req = webob.Request.blank("/other_url")
    return req.get_response(pylonsapp)

The latter would create a new 'environ' and 'start_response' rather
than using the one supplied by Pylons.  I think that's OK but I'm not
100% sure.

There is a 'forward' function in pylons.controllers.util, but it seems
more geared toward calling external WSGI applications, and you would
have to modify request.environ to set the URL, so I'm not sure how
practical it would be in this case.

-- 
Mike Orr <[email protected]>

--

You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.


Reply via email to