1HTTP::Proxy::HeaderFiltUesre(r3)Contributed Perl DocumenHtTaTtPi:o:nProxy::HeaderFilter(3)
2
3
4
6 HTTP::Proxy::HeaderFilter - A base class for HTTP message header fil‐
7 ters
8
10 package MyFilter;
11
12 use base qw( HTTP::Proxy::HeaderFilter );
13
14 # changes the User-Agent header in all requests
15 # this filter must be pushed on the request stack
16 sub filter {
17 my ( $self, $headers, $message ) = @_;
18
19 $message->headers->header( User_Agent => 'MyFilter/1.0' );
20 }
21
22 1;
23
25 The HTTP::Proxy::HeaderFilter class is used to create filters for HTTP
26 request/response headers.
27
28 Creating a HeaderFilter
29
30 A HeaderFilter is just a derived class that implements some methods
31 called by the proxy. Of all the methods presented below, only "fil‐
32 ter()" must be defined in the derived class.
33
34 filter()
35 The signature of the filter() method is the following:
36
37 sub filter { my ( $self, $headers, $message) = @_; ... }
38
39 where $self is the filter object, $headers is a HTTP::Headers
40 object, and $message is either a HTTP::Request or a HTTP::Response
41 object.
42
43 The $headers HTTP::Headers object is the one that will be sent to
44 the client (if the filter is on the response stack) or origin
45 server (if the filter is on the request stack). If $headers is mod‐
46 ified by the filter, the modified headers will be sent to the
47 client or server.
48
49 The init() method (if it exists) is called by the new() construc‐
50 teur to perform all initisalisation tasks. It's called once in the
51 filter lifetime.
52
53 A HTTP::Proxy::HeaderFilter object is a blessed hash, and the base
54 class reserves only hash keys that start with "_hphf".
55
56 new()
57 The constructor is defined for all subclasses. Initialisation tasks
58 (if any) for subclasses should be done in the "init()" method (see
59 below).
60
61 init()
62 This method is called by the "new()" constructeur to perform all
63 initisalisation tasks. It's called once in the filter lifetime.
64
65 It receives all the parameters passed to "new()".
66
67 Standard HeaderFilters
68
69 Standard HTTP::Proxy::HeaderFilter classes are lowercase.
70
71 The following HeaderFilters are included in the HTTP::Proxy distribu‐
72 tion:
73
74 simple
75 This class lets you create a simple header filter from a code ref‐
76 erence.
77
78 standard
79 This is the filter that provides standard headers handling for
80 HTTP::Proxy. It is loaded automatically by HTTP::Proxy.
81
82 Please read each filter's documentation for more details about their
83 use.
84
86 Some methods are available to filters, so that they can eventually use
87 the little knowledge they might have of HTTP::Proxy's internals. They
88 mostly are accessors.
89
90 proxy()
91 Gets a reference to the HTTP::Proxy objects that owns the filter.
92 This gives access to some of the proxy methods.
93
95 Philippe "BooK" Bruhat, <book@cpan.org>.
96
98 HTTP::Proxy, HTTP::Proxy::BodyFilter.
99
101 Copyright 2003-2005, Philippe Bruhat.
102
104 This module is free software; you can redistribute it or modify it
105 under the same terms as Perl itself.
106
107
108
109perl v5.8.8 2006-09-04 HTTP::Proxy::HeaderFilter(3)