25/38

Live example: dragongoserver (3)

So I let the proxy do all the work:

    # remove messages from the server
    my $msg = '&msg=yes';
    $proxy->push_filter(
        host     => 'www.dragongoserver.net',
        path     => '^/game.php',
        response => HTTP::Proxy::BodyFilter::tags->new,
        response => HTTP::Proxy::BodyFilter::simple->new(
            sub { 
                my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
                my $uri = $message->request->uri;
                if( $uri =~ s/$msg//o ) { $msg = '' }
                else { $$dataref =~ s|(</?textarea.*>)|<!-- $1 -->| }
                $$dataref =~ s|(Message:)|<a href="$uri$msg">$1</a>|;
            }
        )
    );

Note that this will fail when the string Message: is split between two chunks of data sent by the server. I'm lucky.