1HTTP::Proxy::BodyFilterU:s:ehrtmClopnatrrsiebru(t3e)d PeHrTlTPD:o:cPurmoexnyt:a:tBioodnyFilter::htmlparser(3)
2
3
4
6 HTTP::Proxy::BodyFilter::htmlparser - Filter using HTML::Parser
7
9 use HTTP::Proxy::BodyFilter::htmlparser;
10
11 # $parser is a HTML::Parser object
12 $proxy->push_filter(
13 mime => 'text/html',
14 response => HTTP::Proxy::BodyFilter::htmlparser->new( $parser );
15 );
16
18 The HTTP::Proxy::BodyFilter::htmlparser lets you create a filter based
19 on the HTML::Parser object of your choice.
20
21 This filter takes a HTML::Parser object as an argument to its
22 constructor. The filter is either read-only or read-write. A read-only
23 filter will not allow you to change the data on the fly. If you request
24 a read-write filter, you'll have to rewrite the response-body
25 completely.
26
27 With a read-write filter, you must recreate the whole body data. This
28 is mainly due to the fact that the HTML::Parser has its own buffering
29 system, and that there is no easy way to correlate the data that
30 triggered the HTML::Parser event and its original position in the chunk
31 sent by the origin server. See below for details.
32
33 Note that a simple filter that modify the HTML text (not the tags) can
34 be created more easily with HTTP::Proxy::BodyFilter::htmltext.
35
36 Creating a HTML::Parser that rewrites pages
37 A read-write filter is declared by passing "rw => 1" to the
38 constructor:
39
40 HTTP::Proxy::BodyFilter::htmlparser->new( $parser, rw => 1 );
41
42 To be able to modify the body of a message, a filter created with
43 HTTP::Proxy::BodyFilter::htmlparser must rewrite it completely. The
44 HTML::Parser object can update a special attribute named "output". To
45 do so, the HTML::Parser handler will have to request the "self"
46 attribute (that is to say, require access to the parser itself) and
47 update its "output" key.
48
49 The following attributes are added to the HTML::Parser object by this
50 filter:
51
52 output
53 A string that will hold the data sent back by the proxy.
54
55 This string will be used as a replacement for the body data only if
56 the filter is read-write, that is to say, if it was initialised
57 with "rw => 1".
58
59 Data should always be appended to "$parser->{output}".
60
61 message
62 A reference to the HTTP::Message that triggered the filter.
63
64 protocol
65 A reference to the HTTP::Protocol object.
66
68 This filter defines three methods, called automatically:
69
70 filter()
71 The filter() method handles all the interactions with the
72 HTML::Parser object.
73
74 init()
75 Initialise the filter with the HTML::Parser object passed to the
76 constructor.
77
78 will_modify()
79 This method returns a boolean value that indicates to the system if
80 it will modify the data passing through. The value is actually the
81 value of the "rw" parameter passed to the constructor.
82
84 HTTP::Proxy, HTTP::Proxy::Bodyfilter,
85 HTTP::Proxy::BodyFilter::htmltext.
86
88 Philippe "BooK" Bruhat, <book@cpan.org>.
89
91 Copyright 2003-2015, Philippe Bruhat.
92
94 This module is free software; you can redistribute it or modify it
95 under the same terms as Perl itself.
96
97
98
99perl v5.36.0 2023-01H-T2T0P::Proxy::BodyFilter::htmlparser(3)