You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Jani M." <mo...@iki.fi> on 2008/03/05 21:12:30 UTC

Adding stickysession cookie on the proxy

Hi,

I've been playing with the idea of adding support for the proxy module 
to add stickysession cookies on behalf of the backend servers. I have 
one case on my hands right now where this would be needed, and I can 
think of this being of use for others too.

The way this would work is that if the proxy would see a response from a 
backend to which no LB cookie was received either from the client or the 
backend, a new cookie would be injected to the response. If the cookie 
already exists, nothing would be done. The cookie when added would be 
based on the balancer and member-name of the current worker

Before I start hacking at the code, I'd like to confirm a few things.

To start with, am I correct in assuming that others might find use for 
this feature? Should I do this, what are my chances of seeing the 
feature added to a future 2.2.x release?

By the way, is it just me, or is the current documentation on how the 
stickysession feature works quite a bit confusing? From the docs I at 
least understand it so that it would be possible to use any generic 
session-id based cookie (whether it's PHPSESSION, JSESSIONID or 
something else). However, both trying this in practice and looking 
through the code gives a rather different view - the format of the 
stickysession cookie appears to be very strict, having to match the 
balancer-name and the route defined for the BalancerMember.

Regardless, back to the subject. I've been going through the proxy code, 
and while it's by no means a simple module, adding this functionality 
doesn't look too difficult. My current plan to attack this would be roughly:

- Add a "setsticky=Off/On" parameter to ProxyPass / ProxySet
- In ap_proxy_http_process_response, add the necessary code to check if 
the cookie exists, and if not, add it. This could likely happen 
somewhere near ap_proxy_read_headers. Moving get_cookie_param from 
mod_proxy_balancer.c to proxy_util.c would allow to reuse it here.

Any thoughts and/or comments?

Cheers,
Jani

Re: Adding stickysession cookie on the proxy

Posted by Nick Gearls <ni...@gmail.com>.
Great idea

Nick


Jani M. wrote:
> Hi,
> 
> I've been playing with the idea of adding support for the proxy module 
> to add stickysession cookies on behalf of the backend servers. I have 
> one case on my hands right now where this would be needed, and I can 
> think of this being of use for others too.
> 
> The way this would work is that if the proxy would see a response from a 
> backend to which no LB cookie was received either from the client or the 
> backend, a new cookie would be injected to the response. If the cookie 
> already exists, nothing would be done. The cookie when added would be 
> based on the balancer and member-name of the current worker
> 
> Before I start hacking at the code, I'd like to confirm a few things.
> 
> To start with, am I correct in assuming that others might find use for 
> this feature? Should I do this, what are my chances of seeing the 
> feature added to a future 2.2.x release?
> 
> By the way, is it just me, or is the current documentation on how the 
> stickysession feature works quite a bit confusing? From the docs I at 
> least understand it so that it would be possible to use any generic 
> session-id based cookie (whether it's PHPSESSION, JSESSIONID or 
> something else). However, both trying this in practice and looking 
> through the code gives a rather different view - the format of the 
> stickysession cookie appears to be very strict, having to match the 
> balancer-name and the route defined for the BalancerMember.
> 
> Regardless, back to the subject. I've been going through the proxy code, 
> and while it's by no means a simple module, adding this functionality 
> doesn't look too difficult. My current plan to attack this would be 
> roughly:
> 
> - Add a "setsticky=Off/On" parameter to ProxyPass / ProxySet
> - In ap_proxy_http_process_response, add the necessary code to check if 
> the cookie exists, and if not, add it. This could likely happen 
> somewhere near ap_proxy_read_headers. Moving get_cookie_param from 
> mod_proxy_balancer.c to proxy_util.c would allow to reuse it here.
> 
> Any thoughts and/or comments?
> 
> Cheers,
> Jani
> 

Re: Adding stickysession cookie on the proxy

Posted by Dirk-Willem van Gulik <di...@webweaving.org>.
On Mar 6, 2008, at 9:05 PM, Jim Jagielski wrote:

>
> On Mar 6, 2008, at 12:45 PM, Jani M. wrote:
>
>> Ruediger Pluem wrote:
>>> You can already do this with mod_headers. Just add
>>> Header add Set-Cookie "MYCOOKIE=SOMEVALUE.% 
>>> {BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED
>>
>> Ah. Don't know why, but for some reason I didn't even think of  
>> using mod_headers for this. Now that you mentioned this, it seems  
>> quite obvious.
>>
>>> No need for additional code IMHO.
>>
>> I agree. "Native" support for this in proxy module directly would  
>> be nice, but not necessarily worth the effort.
>>
>
> The advantage of mod_headers is more flexibility that what could
> be "comfortably" added to the proxy module itself as well...
>
> This comes up maybe once or twice a year... I think I'll add
> it to my standard Apache 2.2 Proxy module presentation ;)

Or a how-to in the docs - in the proxy section.

Dw

Re: Adding stickysession cookie on the proxy

Posted by Jim Jagielski <ji...@jaguNET.com>.
On Mar 6, 2008, at 3:10 PM, Joshua Slive wrote:

> On Thu, Mar 6, 2008 at 3:05 PM, Jim Jagielski <ji...@apache.org> wrote:
>
>> The advantage of mod_headers is more flexibility that what could
>> be "comfortably" added to the proxy module itself as well...
>>
>> This comes up maybe once or twice a year... I think I'll add
>> it to my standard Apache 2.2 Proxy module presentation ;)
>
> How about adding it to the documentation (or at least the wiki)?
>

There too...



Re: Adding stickysession cookie on the proxy

Posted by Joshua Slive <jo...@slive.ca>.
On Thu, Mar 6, 2008 at 3:05 PM, Jim Jagielski <ji...@apache.org> wrote:

>  The advantage of mod_headers is more flexibility that what could
>  be "comfortably" added to the proxy module itself as well...
>
>  This comes up maybe once or twice a year... I think I'll add
>  it to my standard Apache 2.2 Proxy module presentation ;)

How about adding it to the documentation (or at least the wiki)?

Joshua.

Re: Adding stickysession cookie on the proxy

Posted by Jim Jagielski <ji...@apache.org>.
On Mar 6, 2008, at 12:45 PM, Jani M. wrote:

> Ruediger Pluem wrote:
>> You can already do this with mod_headers. Just add
>> Header add Set-Cookie "MYCOOKIE=SOMEVALUE.% 
>> {BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED
>
> Ah. Don't know why, but for some reason I didn't even think of using  
> mod_headers for this. Now that you mentioned this, it seems quite  
> obvious.
>
>> No need for additional code IMHO.
>
> I agree. "Native" support for this in proxy module directly would be  
> nice, but not necessarily worth the effort.
>

The advantage of mod_headers is more flexibility that what could
be "comfortably" added to the proxy module itself as well...

This comes up maybe once or twice a year... I think I'll add
it to my standard Apache 2.2 Proxy module presentation ;)


Re: Adding stickysession cookie on the proxy

Posted by "Jani M." <mo...@iki.fi>.
Ruediger Pluem wrote:
> You can already do this with mod_headers. Just add
> 
> Header add Set-Cookie "MYCOOKIE=SOMEVALUE.%{BALANCER_WORKER_ROUTE}e; 
> path=/;" env=BALANCER_ROUTE_CHANGED

Ah. Don't know why, but for some reason I didn't even think of using 
mod_headers for this. Now that you mentioned this, it seems quite obvious.

> No need for additional code IMHO.

I agree. "Native" support for this in proxy module directly would be 
nice, but not necessarily worth the effort.

Thanks,
Jani

Re: Adding stickysession cookie on the proxy

Posted by Ruediger Pluem <rp...@apache.org>.

On 03/05/2008 09:12 PM, Jani M. wrote:
> Hi,
> 
> I've been playing with the idea of adding support for the proxy module 
> to add stickysession cookies on behalf of the backend servers. I have 
> one case on my hands right now where this would be needed, and I can 
> think of this being of use for others too.
> 
> The way this would work is that if the proxy would see a response from a 
> backend to which no LB cookie was received either from the client or the 
> backend, a new cookie would be injected to the response. If the cookie 
> already exists, nothing would be done. The cookie when added would be 
> based on the balancer and member-name of the current worker

You can already do this with mod_headers. Just add

Header add Set-Cookie "MYCOOKIE=SOMEVALUE.%{BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED

to the proxy block that defines your balancer, use

ProxySet  stickysession=MYCOOKIE

and define the routes of your BalancerMembers accordingly

No need for additional code IMHO.

Regards

RĂ¼diger


Re: Adding stickysession cookie on the proxy

Posted by "Akins, Brian" <Br...@turner.com>.
On 3/5/08 3:12 PM, "Jani M." <mo...@iki.fi> wrote:

> To start with, am I correct in assuming that others might find use for
> this feature? 

We do this in our "homegrown" proxy.  One less thing for the java guys to
think about...  

-- 
Brian Akins
Chief Operations Engineer
Turner Digital Media Technologies