X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=etc%2Fmod_perl%2FMyApache2%2FCopyCookie.pm;h=3e29647b559845b6e2d2a621e01fe7061b5d2e1f;hb=91f73c93cb0f226e251db72219b67ed416c1f639;hp=730abc3991daf5982a7a5336c5be3831e6e93fec;hpb=b12832795453354cbde4ce942bdec7e246eb90de;p=mkws-moved-to-github.git diff --git a/etc/mod_perl/MyApache2/CopyCookie.pm b/etc/mod_perl/MyApache2/CopyCookie.pm index 730abc3..3e29647 100644 --- a/etc/mod_perl/MyApache2/CopyCookie.pm +++ b/etc/mod_perl/MyApache2/CopyCookie.pm @@ -1,16 +1,41 @@ - package MyApache2::CopyCookie; - use Apache2::Filter (); - use Apache2::RequestRec (); - use APR::Table (); +package MyApache2::CopyCookie; - use Apache2::Const -compile => qw(OK); +use Apache2::Filter (); +use Apache2::RequestRec (); +use APR::Table (); - sub handler { - my $f = shift; +use Apache2::Const -compile => qw(OK); - my $cookie = $f->r->headers_out->get('Set-Cookie'); - $f->r->headers_out->set('X-Set-Cookie', $cookie); - return Apache2::Const::OK; - } - 1; +use constant BUFF_LEN => 1024; +sub handler { + my $f = shift; + + # If the server generated a new cookie, make it available in a + # header other than the magic "Cookie" that clients can't read. + my $ho = $f->r->headers_out; + my $cookie = $ho->get('Set-Cookie'); + if (defined $cookie && $cookie ne "") { + $ho->set('X-Set-Cake', $cookie); + } + + # If the client sent an existing cookie as X-Cake, but didn't + # set Cookie, copy the former to the latter. + my $hi = $f->r->headers_in; + $cookie = $hi->get('Cookie'); + if (!defined $cookie || $cookie eq "") { + $cookie = $hi->get('X-Cake'); + if (defined $cookie && $cookie ne "") { + warn "copying X-Cake '$cookie' to Cookie"; + $hi->set('Cookie', $cookie); + } + } + + while ($f->read(my $buffer, BUFF_LEN)) { + $f->print($buffer); + } + + return Apache2::Const::OK; +} + +1;