You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "John D.Lima" <li...@5cats.org> on 2004/03/12 17:28:50 UTC

[mp2] PerlPreConnectionHandler and subrequests detection?

I have a PerlPreConnectionHandler running on a proxy vhost (w/ 
mod_proxy),
acting much like the User Guide example that blocks clients by their IP.
I'd like it to behave differently if the connection of due to a 
subrequest
or not.

For clarity (?): my PerlPreConnectionHandler works great on browser 
requests
coming into the proxy, but it runs again when the server response to 
the proxied
request returns _to the proxy_.  In this server response case I want to 
do
something slightly different based on the _server's_ IP.  But I don't 
know how to
easily determine if this (server response) connection is actually due 
to the
proxy's own subrequest, and not another client browser connecting.

I could move this IP-checking code into the PerlPostReadRequestHandler, 
but it'd
be nicer to deal with the connection level for this, not per-request 
once it's
into the HTTP handlers.

Cheers,
-jd.


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp2] PerlPreConnectionHandler and subrequests detection?

Posted by Stas Bekman <st...@stason.org>.
John D.Lima wrote:
> 
> On Mar 12, 2004, at 5:12 PM, Stas Bekman wrote:
> 
>> John D.Lima wrote:
> 
> *snip*
> 
>>> For clarity (?): my PerlPreConnectionHandler works great on browser 
>>> requests
>>> coming into the proxy, but it runs again when the server response to 
>>> the proxied
>>> request returns _to the proxy_.  In this server response case I want 
>>> to do
>>> something slightly different based on the _server's_ IP.  But I don't 
>>> know how to
>>> easily determine if this (server response) connection is actually due 
>>> to the
>>> proxy's own subrequest, and not another client browser connecting.
>>
>>
>> I don't think that qualifies as an Apache sub-request. Are you talking 
>> about "sub-request" to a remote server? If it's a local subrequest, it 
>> won't use a new connection, and therefore won't invoke 
>> PerlPreConnectionHandler.
> 
> 
> yep, my mistake for calling it a subrequest...
> 
>> If that's a remote request (like LWP'ing), why do you say that the 
>> response from the remote server creates a new connection?
> 
> 
> Yes, this is (mostly) the case.  The remote server response to the proxy 
> is apparently
> due to mod_proxy's action just after the fixup phase of the original 
> request into the
> proxy.  I'm saying the remote server response appears to make another 
> connection to the
> proxy because the same PerlPreConnectionHandler runs a second time.  

Yup, I've skimmed through the mod_proxy source and that's exactly what it does.

> It would seem the PerlPreConnectionHandler catches both.  BUT how would 
> I distinguish
> between the two, aside from IP?

It seems that it'll use the same connection pool, server and id when it 
proxies an HTTP request. from proxy_http.c:

         /* the socket is now open, create a new backend server connection */
         *origin = ap_run_create_connection(c->pool, r->server, p_conn->sock,
                                            r->connection->id,
                                            r->connection->sbh,
                                            c->bucket_alloc);

So you could probably try one of the following:

* set a note in $c->base_server and then read it in the second connection
* track $c->id (should be the same id in both)
* set user data in the $c->pool and read it in the second connection

I haven't tested any of these, just thinking that this might be right from 
looking at proxy_http.c and other source files under httpd-2.0/modules/proxy/

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp2] PerlPreConnectionHandler and subrequests detection?

Posted by "John D.Lima" <li...@5cats.org>.
On Mar 12, 2004, at 5:12 PM, Stas Bekman wrote:

> John D.Lima wrote:
*snip*
>> For clarity (?): my PerlPreConnectionHandler works great on browser 
>> requests
>> coming into the proxy, but it runs again when the server response to 
>> the proxied
>> request returns _to the proxy_.  In this server response case I want 
>> to do
>> something slightly different based on the _server's_ IP.  But I don't 
>> know how to
>> easily determine if this (server response) connection is actually due 
>> to the
>> proxy's own subrequest, and not another client browser connecting.
>
> I don't think that qualifies as an Apache sub-request. Are you talking 
> about "sub-request" to a remote server? If it's a local subrequest, it 
> won't use a new connection, and therefore won't invoke 
> PerlPreConnectionHandler.

yep, my mistake for calling it a subrequest...

> If that's a remote request (like LWP'ing), why do you say that the 
> response from the remote server creates a new connection?

Yes, this is (mostly) the case.  The remote server response to the 
proxy is apparently
due to mod_proxy's action just after the fixup phase of the original 
request into the
proxy.  I'm saying the remote server response appears to make another 
connection to the
proxy because the same PerlPreConnectionHandler runs a second time.  
Here's what I see:

CLIENT: sends request through proxy.
PROXY:
1 my PerlPreConnectionHandler runs
	* debug shows CLIENT IP
	* I set a connection note for later
2 various HTTP phases run...
3 my PerlFixupHandler runs
	* I see my connection note from earlier CLIENT connect
4 <mod_proxy proxies>
5 my PerlPreConnectionHandler runs *again*
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	* debug shows REMOTE SERVER IP
	* there is NO connection note
	* I set a (different) connection note
6 my RequestOutputFilter runs
	* I see my connection note from ealier CLIENT connect

In the above PROXY (4), it appears that mod_proxy dutifully proxies
the CLIENT request to the REMOTE SERVER;

In PROXY (5), the PROXY receives the REMOTE SERVER response -- where
it definitely runs my PerlPreConnectionHandler.  I believe this is
a different connection than that seen in the earlier run of my
PerlPreConnectionHandler.

In PROXY (6), just as the proxy is going to send the response to
the client, I see that indeed, the connection note is from the
first run of my PerlPreConnectionHandler from the original CLIENT
connect.

> In any case, I don't think you can gain anything useful besides IP 
> during the preconnection phase.

I want to do something -- based on client IP -- at client connections 
_to the proxy_,
and I want to do something *else* -- based on the (remote) server's IP 
-- with the
server response to the proxied request back through the proxy.  Both 
these actions
are from the proxy perspective.

My workaround for now is to run my IP-based stuff from the 
PerlPostReadRequestHandler.
But while allowing the proxy to do something based on the client IP 
early on, this
precludes the possibility of also doing something IP-based with the 
remote server
response traveling back through the proxy.

It would seem the PerlPreConnectionHandler catches both.  BUT how would 
I distinguish
between the two, aside from IP?

Cheers,
-jd.


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp2] PerlPreConnectionHandler and subrequests detection?

Posted by Stas Bekman <st...@stason.org>.
John D.Lima wrote:
> I have a PerlPreConnectionHandler running on a proxy vhost (w/ mod_proxy),
> acting much like the User Guide example that blocks clients by their IP.
> I'd like it to behave differently if the connection of due to a subrequest
> or not.
 >
> For clarity (?): my PerlPreConnectionHandler works great on browser 
> requests
> coming into the proxy, but it runs again when the server response to the 
> proxied
> request returns _to the proxy_.  In this server response case I want to do
> something slightly different based on the _server's_ IP.  But I don't 
> know how to
> easily determine if this (server response) connection is actually due to 
> the
> proxy's own subrequest, and not another client browser connecting.

I don't think that qualifies as an Apache sub-request. Are you talking about 
"sub-request" to a remote server? If it's a local subrequest, it won't use a 
new connection, and therefore won't invoke PerlPreConnectionHandler.

If that's a remote request (like LWP'ing), why do you say that the response 
from the remote server creates a new connection?

In any case, I don't think you can gain anything useful besides IP during the 
preconnection phase.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html