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;
14 # If the server generated a new cookie, make it available in a
15 # header other than the magic "Cookie" that clients can't read.
16 my $ho = $f->r->headers_out;
17 my $cookie = $ho->get('Set-Cookie');
18 if (defined $cookie && $cookie ne "") {
19 $ho->set('X-Set-Cake', $cookie);
22 # If the client sent an existing cookie as X-Cake, but didn't
23 # set Cookie, copy the former to the latter.
24 my $hi = $f->r->headers_in;
25 $cookie = $hi->get('Cookie');
26 if (!defined $cookie || $cookie eq "") {
27 $cookie = $hi->get('X-Cake');
28 if (defined $cookie && $cookie ne "") {
29 warn "copying X-Cake '$cookie' to Cookie";
30 $hi->set('Cookie', $cookie);
34 while ($f->read(my $buffer, BUFF_LEN)) {
38 return Apache2::Const::OK;