File: outline.pl

package info (click to toggle)
libhttp-proxy-perl 0.304-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 720 kB
  • sloc: perl: 2,576; makefile: 4
file content (43 lines) | stat: -rwxr-xr-x 1,125 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w
use HTTP::Proxy qw( :log );
use HTTP::Proxy::BodyFilter::htmlparser;
use HTML::Parser;
use strict;

my $parser = HTML::Parser->new( api_version => 3 );
$parser->handler(
    start_document => sub { my $self = shift; $self->{print} = 1 },
    "self"
);
$parser->handler(
    start => sub {
        my ( $self, $tag, $text ) = @_;
        $self->{print} = 1 if $tag =~ /^h\d/;
        $self->{output} .= $text if $self->{print};
        $self->{print} = 0 if $tag eq 'body';
    },
    "self,tagname,text"
);
$parser->handler(
    end => sub {
        my ( $self, $tag, $text ) = @_;
        $self->{print} = 1 if $tag eq 'body';
        $self->{output} .= $text if $self->{print};
        $self->{print} = 0 if $tag =~ /^h\d/;
    },
    "self,tagname,text"
);
$parser->handler(
    default => sub {
        my ( $self, $text ) = @_;
        $self->{output} .= $text if $self->{print};
    },
    "self,text"
);

my $filter = HTTP::Proxy::BodyFilter::htmlparser->new( $parser, rw => 1 );

my $proxy = HTTP::Proxy->new(@ARGV);
$proxy->push_filter( mime => 'text/html', response => $filter );
$proxy->start;