1 package MyApache2::CopyCookie;
3 use Apache2::Filter ();
4 use Apache2::RequestRec ();
7 use Apache2::Const -compile => qw(OK);
9 use constant BUFF_LEN => 1024;
13 warn "in MyApache2::CopyCookie (f=$f)";
15 # If the server generated a new cookie, make it available in a
16 # header other than the magic "Cookie" that clients can't read.
17 my $ho = $f->r->headers_out;
18 my $cookie = $ho->get('Set-Cookie');
19 if (defined $cookie && $cookie ne "") {
20 $ho->set('X-Set-Cake', $cookie);
23 # If the client sent an existing cookie as X-Cake, but didn't
24 # set Cookie, copy the former to the latter.
25 my $hi = $f->r->headers_in;
26 $cookie = $hi->get('Cookie');
27 if (!defined $cookie || $cookie eq "") {
28 $cookie = $hi->get('X-Cake');
29 if (defined $cookie && $cookie ne "") {
30 warn "copying X-Cake '$cookie' to Cookie";
31 $hi->set('Cookie', $cookie);
35 while ($f->read(my $buffer, BUFF_LEN)) {
39 return Apache2::Const::OK;