Hi, I have found this in the Archives which sounds a lot like my problem.
http://www.mail-archive.com/[email protected]/msg03213.html There were no responses to this post though. So I modified things to make sure I knew what headers were being copied as below sub proxy_handler { my $r = shift; my $request = HTTP::Request->new($r->method, $r->uri); $r->log_error("Start of Request"); $r->headers_in->do(sub { $request->header(@_); $r->log_error(@_); }); $r->log_error("End of Request\n\n"); I got a Cookie: header as I hoped where that would exist. [Fri Feb 8 16:52:51 2002] [error] Start of Request [Fri Feb 8 16:52:51 2002] [error] Acceptimage/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png [Fri Feb 8 16:52:51 2002] [error] Accept-Charsetiso-8859-1,*,utf-8 [Fri Feb 8 16:52:51 2002] [error] Accept-Encodinggzip [Fri Feb 8 16:52:51 2002] [error] Accept-Languageen,de,de-DE,is [Fri Feb 8 16:52:51 2002] [error] CookieXc0&2126258&1=1013218362&107&7893 [Fri Feb 8 16:52:51 2002] [error] Hostbanners.pennyweb.com [Fri Feb 8 16:52:51 2002] [error] Proxy-ConnectionKeep-Alive [Fri Feb 8 16:52:51 2002] [error] Refererhttp://www.itsyourturn.com/iyt.dll?status?? [Fri Feb 8 16:52:51 2002] [error] User-AgentMozilla/4.72 [en] (Win98; I) [Fri Feb 8 16:52:51 2002] [error] End of Request [Fri Feb 8 16:52:51 2002] [error] Actual Proxy Request [Fri Feb 8 16:52:51 2002] [error] GET http://banners.pennyweb.com/dot.gif Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png Accept-Charset: iso-8859-1,*,utf-8 Accept-Encoding: gzip Accept-Language: en,de,de-DE,is Host: banners.pennyweb.com Referer: http://www.itsyourturn.com/iyt.dll?status?? User-Agent: Mozilla/4.72 [en] (Win98; I) Cookie: Xc0&2126258&1=1013218362&107&7893 Proxy-Connection: Keep-Alive After I did this suddenly I started getting cookies to work, esp with sites like itsyourturn.com that uses a cookie to keep track of a logged in user. When I removed my $r->log_error debugging info, then the cookies didn't get sent back to the client. Bizzare, but it is consistent, and I tested with IE 5.5, Netscape 4.7, and Mozilla. I am using Apache 1.3.23 and mod_perl 1.2.6 with EVERYTHING=1 and PERL_TRACE=1 My Apache has mod proxy, but it isn't enabled in the config. Is this enough information to make some guesses? Below is the whole thing with my minor changes. Thanks, Eric package Apache::AdBlocker; # file: Apache/AdBlocker.pm use strict; use vars qw(@ISA $VERSION); use Apache::Constants qw(:common); use GD (); use Image::Size qw(imgsize); use LWP::UserAgent (); @ISA = qw(LWP::UserAgent); $VERSION = '1.00'; my $UA = __PACKAGE__->new; $UA->agent(join "/", __PACKAGE__, $VERSION); sub redirect_ok {0} my $Ad = join "|", qw{ads? advertisements? banners? adv promotions? atwola }; sub handler { my $r = shift; return DECLINED unless $r->proxyreq; $r->handler("perl-script"); #ok, let's do it $r->push_handlers(PerlHandler => \&proxy_handler); return OK; } sub proxy_handler { my $r = shift; my $request = HTTP::Request->new($r->method, $r->uri); $r->log_error("Start of Request"); $r->headers_in->do(sub { $request->header(@_); $r->log_error(@_); }); $r->log_error("End of Request\n\n"); # copy POST data, if any if($r->method eq 'POST') { my $len = $r->header_in('Content-length'); my $buf; $r->read($buf, $len); $request->content($buf); } my $req_string = $request->as_string(); $r->log_error("\n\nActual Proxy Request"); $r->log_error($req_string); $req_string=''; my $response = $UA->request($request); # the request is proxyed to the remote host site here. # the $response object *should* contain a Set Cookie Header $r->content_type($response->header('Content-type')); #feed response back into our request_rec* $r->status($response->code); $r->status_line(join " ", $response->code, $response->message); $response->scan(sub { $r->header_out(@_); }); # $r->header_out should fill headers from $response, and should include Set Cookie if it exists. if ($r->header_only) { $r->send_http_header(); # sends proxy request if HEAD request back to client return OK; } my $content = \$response->content; if($r->content_type =~ /^image/ and $r->uri =~ /\b($Ad)\b/i) { block_ad($content); $r->content_type("image/gif"); } $r->content_type('text/html') unless $$content; $r->send_http_header; # sends proxy request back to client $r->print($$content || $response->error_as_HTML); $r->print("<h1>Blocked by Pooh</H1>"); return OK; } sub block_ad { my $data = shift; my($x, $y) = imgsize($data); my $im = GD::Image->new($x,$y); my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,0); my $red = $im->colorAllocate(255,0,0); $im->transparent($white); $im->string(GD::gdLargeFont(),5,5,"Blocked by Pooh",$red); $im->rectangle(0,0,$x-1,$y-1,$black); $$data = $im->png; } 1; __END__ http://www.kwinternet.com/eric (250) 655 - 9513 (PST Time Zone)
