Overwriting a cookie in request header

2009-11-17 Thread Sinha, Ritu
I have an Apache module in which I am trying to overwrite the value of a 
cookie. I have tried different methods of the APR::Table without success.
Here are the approaches that I have tried:

[1] $r-headers_out-set(Set-Cookie, $cookie);

Here, $cookie has the name=value pair with the name of the cookie that needs to 
be overwritten. The outcome is 2 cookies with the same name.

[2] $cookie = $r-headers_in-{Cookie};
search-and-replace the cookie value in $cookie
$r-headers_out-{Cookie}=$cookie;

Does not do anything to the existing cookie ... does not even add a new cookie.

[3] $cookie = $r-headers_in-{Cookie};
@cookies = split(/;/,$cookie);
$r-headers_out-clear();
 add cookies one-by-one replacing the value of the cookie in question using  
$r-headers_out-set(Set-Cookie, $cookie); 

The web application does not work ... seems like clearing the header creates 
problems.

Any pointers would be really helpful.

Thanks,
Ritu






Re: Overwriting a cookie in request header

2009-11-17 Thread Devin Teske
Try this:

use CGI::Util;
my $domain = mydomain.com;
# Add cookie to HTTP response
$r-err_headers_out-add(Set-Cookie =
cookie_name=cookie_value
. ; path=/
. ; expires=
. CGI::Util::expires('+60m', 'cookie');
. ; domain=$domain;

This will create a cookie and add it to the HTTP response header, which
will then expire in 60 minutes on the client-side by the browser.

Now let's say that you want to then kill that cookie (or perhaps change
its value, or perhaps just update it so that it doesn't expire). This is
done by passing back to the client (in a new HTTP response) a cookie
with (a) the same name, (b) the same domain, and (c) the same path.
These three key values (cookie name, path, and domain) are what create a
unique cookie (and hence why you've ended up with two cookies ... it's
not enough to simply pass back a name/value pair).

Here's an example for later deleting that same cookie (going with the
above example, let's say the cookie's name is cookie_name).

use CGI::Util;
my $domain = mydomain.com;
# Tell the browser to delete cookie 'cookie_name' (set previously)
$r-err_headers_out-add(Set-Cookie =
cookie_name=
. ; path=/
. ; expires=
. CGI::Util::expires('now', 'cookie');
. ; domain=$domain;

The expiration value of 'now' is translated by the expires() sub-routine
into a valid cookie expiration date/time-string and facilitates the
expiration of the cookie at the browser-side.

Again, remember that the cookie_name, path, and domain MUST match that
of the original cookie, else nothing will happen.

Modifying the value of an existing cookie is very similar... just pass
back a cookie with matching name/path/domain with some new value and
with an expiration sometime in the future... the browser will overwrite
the old cookie with the new (again, because the name/path/domain match).
--
Devin





On Tue, 2009-11-17 at 10:09 -0500, Sinha, Ritu wrote:
 I have an Apache module in which I am trying to overwrite the value of
 a cookie. I have tried different methods of the APR::Table without
 success.
 Here are the approaches that I have tried:
  
 [1] $r-headers_out-set(Set-Cookie, $cookie);
  
 Here, $cookie has the name=value pair with the name of the cookie that
 needs to be overwritten. The outcome is 2 cookies with the same name.
  
 [2] $cookie = $r-headers_in-{Cookie};
 search-and-replace the cookie value in $cookie
 $r-headers_out-{Cookie}=$cookie;
  
 Does not do anything to the existing cookie … does not even add a new
 cookie.
  
 [3] $cookie = $r-headers_in-{Cookie};
 @cookies = split(/;/,$cookie);
 $r-headers_out-clear();
  add cookies one-by-one replacing the value of the cookie in question
 using  $r-headers_out-set(Set-Cookie, $cookie); 
  
 The web application does not work … seems like clearing the header
 creates problems.
  
 Any pointers would be really helpful.
  
 Thanks,
 Ritu
  
  
  
  
-- 
Cheers,
Devin Teske

- CONTACT INFORMATION -
Field Engineer
FIS - Vicor Business Unit
626-573-6040 Office
510-735-5650 Mobile
devin.te...@metavante.com

- LEGAL DISCLAIMER -
This message  contains confidential  and proprietary  information
of the sender,  and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person  is strictly prohibited.  If you have  received this
message in error,  please notify  the e-mail sender  immediately,
and delete the original message without making a copy.

- END TRANSMISSION -



Re: Overwriting a cookie in request header

2009-11-17 Thread Devin Teske
Oops... forgot ending right-paren to add().

Replace (in all examples):

. ; domain=$domain;

with:
. ; domain=$domain);

^_^
--
Devin


On Tue, 2009-11-17 at 07:31 -0800, Devin Teske wrote:
 Try this:
 
 use CGI::Util;
 my $domain = mydomain.com;
 # Add cookie to HTTP response
 $r-err_headers_out-add(Set-Cookie =
   cookie_name=cookie_value
   . ; path=/
   . ; expires=
   . CGI::Util::expires('+60m', 'cookie');
   . ; domain=$domain;
 
 This will create a cookie and add it to the HTTP response header, which
 will then expire in 60 minutes on the client-side by the browser.
 
 Now let's say that you want to then kill that cookie (or perhaps change
 its value, or perhaps just update it so that it doesn't expire). This is
 done by passing back to the client (in a new HTTP response) a cookie
 with (a) the same name, (b) the same domain, and (c) the same path.
 These three key values (cookie name, path, and domain) are what create a
 unique cookie (and hence why you've ended up with two cookies ... it's
 not enough to simply pass back a name/value pair).
 
 Here's an example for later deleting that same cookie (going with the
 above example, let's say the cookie's name is cookie_name).
 
 use CGI::Util;
 my $domain = mydomain.com;
 # Tell the browser to delete cookie 'cookie_name' (set previously)
 $r-err_headers_out-add(Set-Cookie =
   cookie_name=
   . ; path=/
   . ; expires=
   . CGI::Util::expires('now', 'cookie');
   . ; domain=$domain;
 
 The expiration value of 'now' is translated by the expires() sub-routine
 into a valid cookie expiration date/time-string and facilitates the
 expiration of the cookie at the browser-side.
 
 Again, remember that the cookie_name, path, and domain MUST match that
 of the original cookie, else nothing will happen.
 
 Modifying the value of an existing cookie is very similar... just pass
 back a cookie with matching name/path/domain with some new value and
 with an expiration sometime in the future... the browser will overwrite
 the old cookie with the new (again, because the name/path/domain match).
 --
 Devin
 
 
 
 
 
 On Tue, 2009-11-17 at 10:09 -0500, Sinha, Ritu wrote:
  I have an Apache module in which I am trying to overwrite the value of
  a cookie. I have tried different methods of the APR::Table without
  success.
  Here are the approaches that I have tried:
   
  [1] $r-headers_out-set(Set-Cookie, $cookie);
   
  Here, $cookie has the name=value pair with the name of the cookie that
  needs to be overwritten. The outcome is 2 cookies with the same name.
   
  [2] $cookie = $r-headers_in-{Cookie};
  search-and-replace the cookie value in $cookie
  $r-headers_out-{Cookie}=$cookie;
   
  Does not do anything to the existing cookie … does not even add a new
  cookie.
   
  [3] $cookie = $r-headers_in-{Cookie};
  @cookies = split(/;/,$cookie);
  $r-headers_out-clear();
   add cookies one-by-one replacing the value of the cookie in question
  using  $r-headers_out-set(Set-Cookie, $cookie); 
   
  The web application does not work … seems like clearing the header
  creates problems.
   
  Any pointers would be really helpful.
   
  Thanks,
  Ritu
   
   
   
   
-- 
Cheers,
Devin Teske

- CONTACT INFORMATION -
Field Engineer
FIS - Vicor Business Unit
626-573-6040 Office
510-735-5650 Mobile
devin.te...@metavante.com

- LEGAL DISCLAIMER -
This message  contains confidential  and proprietary  information
of the sender,  and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person  is strictly prohibited.  If you have  received this
message in error,  please notify  the e-mail sender  immediately,
and delete the original message without making a copy.

- END TRANSMISSION -



RE: Overwriting a cookie in request header

2009-11-17 Thread Sinha, Ritu
Thanks Devin  Thomas. The 3 keys that define a unique cookie really helped 
understand the behavior. My module is working as expected now.

--Ritu 

-Original Message-
From: Devin Teske [mailto:dte...@vicor.com] 
Sent: Tuesday, November 17, 2009 10:36 AM
To: Sinha, Ritu
Cc: 'modperl@perl.apache.org'
Subject: Re: Overwriting a cookie in request header

Oops... forgot ending right-paren to add().

Replace (in all examples):

. ; domain=$domain;

with:
. ; domain=$domain);

^_^
--
Devin


On Tue, 2009-11-17 at 07:31 -0800, Devin Teske wrote:
 Try this:
 
 use CGI::Util;
 my $domain = mydomain.com;
 # Add cookie to HTTP response
 $r-err_headers_out-add(Set-Cookie =
   cookie_name=cookie_value
   . ; path=/
   . ; expires=
   . CGI::Util::expires('+60m', 'cookie');
   . ; domain=$domain;
 
 This will create a cookie and add it to the HTTP response header, which
 will then expire in 60 minutes on the client-side by the browser.
 
 Now let's say that you want to then kill that cookie (or perhaps change
 its value, or perhaps just update it so that it doesn't expire). This is
 done by passing back to the client (in a new HTTP response) a cookie
 with (a) the same name, (b) the same domain, and (c) the same path.
 These three key values (cookie name, path, and domain) are what create a
 unique cookie (and hence why you've ended up with two cookies ... it's
 not enough to simply pass back a name/value pair).
 
 Here's an example for later deleting that same cookie (going with the
 above example, let's say the cookie's name is cookie_name).
 
 use CGI::Util;
 my $domain = mydomain.com;
 # Tell the browser to delete cookie 'cookie_name' (set previously)
 $r-err_headers_out-add(Set-Cookie =
   cookie_name=
   . ; path=/
   . ; expires=
   . CGI::Util::expires('now', 'cookie');
   . ; domain=$domain;
 
 The expiration value of 'now' is translated by the expires() sub-routine
 into a valid cookie expiration date/time-string and facilitates the
 expiration of the cookie at the browser-side.
 
 Again, remember that the cookie_name, path, and domain MUST match that
 of the original cookie, else nothing will happen.
 
 Modifying the value of an existing cookie is very similar... just pass
 back a cookie with matching name/path/domain with some new value and
 with an expiration sometime in the future... the browser will overwrite
 the old cookie with the new (again, because the name/path/domain match).
 --
 Devin
 
 
 
 
 
 On Tue, 2009-11-17 at 10:09 -0500, Sinha, Ritu wrote:
  I have an Apache module in which I am trying to overwrite the value of
  a cookie. I have tried different methods of the APR::Table without
  success.
  Here are the approaches that I have tried:
   
  [1] $r-headers_out-set(Set-Cookie, $cookie);
   
  Here, $cookie has the name=value pair with the name of the cookie that
  needs to be overwritten. The outcome is 2 cookies with the same name.
   
  [2] $cookie = $r-headers_in-{Cookie};
  search-and-replace the cookie value in $cookie
  $r-headers_out-{Cookie}=$cookie;
   
  Does not do anything to the existing cookie ... does not even add a new
  cookie.
   
  [3] $cookie = $r-headers_in-{Cookie};
  @cookies = split(/;/,$cookie);
  $r-headers_out-clear();
   add cookies one-by-one replacing the value of the cookie in question
  using  $r-headers_out-set(Set-Cookie, $cookie); 
   
  The web application does not work ... seems like clearing the header
  creates problems.
   
  Any pointers would be really helpful.
   
  Thanks,
  Ritu
   
   
   
   
-- 
Cheers,
Devin Teske

- CONTACT INFORMATION -
Field Engineer
FIS - Vicor Business Unit
626-573-6040 Office
510-735-5650 Mobile
devin.te...@metavante.com

- LEGAL DISCLAIMER -
This message  contains confidential  and proprietary  information
of the sender,  and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person  is strictly prohibited.  If you have  received this
message in error,  please notify  the e-mail sender  immediately,
and delete the original message without making a copy.

- END TRANSMISSION -


Re: AJAX pseudo-push

2009-11-17 Thread Tom Schindl
Nicolas George schrieb:
 Hi.
 
 There is an increasingly popular technique to emulate server-initiated push
 over HTTP. I'm sure everyone here knows it well, but for the sake of
 completeness: the clients sends a XMLHttpRequest to the server in the
 background; the server does not answer it immediately, but keeps it for
 later when there is actually something to say to the client; if the request
 timeouts, the client re-sends it.
 
 I am wondering if this technique is usable with Apache in general and
 mod_perl in particular.
 
 The obvious solution is to have the request handler sleep until it has
 something to answer does not work, since it requires a worker thread and a
 perl interpreter for each waiting client, and perl interpreters are few and
 expensive.
 
 The ideal solution would be if some part of the request handler could put
 the current request (A) on hold. Later, the handler for another request
 (B) could retrieve the request A and generate an answer for it, or at least
 wake it up.
 

What you describe here is called Continuations in Java world :-)

Tom

http://docs.codehaus.org/display/JETTY/Continuations


Re: AJAX pseudo-push

2009-11-17 Thread Andy Armstrong
On 17 Nov 2009, at 16:49, Tom Schindl wrote:
 What you describe here is called Continuations in Java world :-)

Continuations in the Java world are the same as continuations everywhere - but 
not quite what the OP described :)

http://en.wikipedia.org/wiki/Comet_(programming)

-- 
Andy Armstrong, Hexten





Re: code in perl sections executed twice in same process?

2009-11-17 Thread E R
The perl sections don't seem to be executed in the children.

Is there a way to determine which pass you are in?

For large mod_perl apps, is there a way to avoid loading your code in twice?

Note I am using mod_perl 1.3.41.

Thanks,
ER

On Mon, Nov 16, 2009 at 4:41 PM, André Warnier a...@ice-sa.com wrote:
 E R wrote:
 ...

 Is this normal, and what can I do so that the code in Perl
 sections is only executed once in the parent process?

 I believe it is normal, in the sense that Apache actually parses its
 configuration at least twice : one time just for checking, then it throws
 everything away and parses it a second time for real.

 Then it will even (probably) run your section again, each time it starts a
 new child process.

 You probably really want to read the following 2 pages :
 http://perl.apache.org/docs/2.0/user/handlers/server.html
 http://perl.apache.org/docs/2.0/user/config/custom.html




Re: code in perl sections executed twice in same process?

2009-11-17 Thread Adam Prime

E R wrote:

The perl sections don't seem to be executed in the children.


use a PerlChildInitHandler if you want to run code in the children.


Is there a way to determine which pass you are in?

For large mod_perl apps, is there a way to avoid loading your code in twice?

Note I am using mod_perl 1.3.41.


In mp1, use $Apache::Server::Starting, and $Apache::Server::ReStarting. 
 see here:


http://perl.apache.org/docs/1.0/guide/config.html#Apache_Restarts_Twice_On_Start

Adam