1HTTP::Config(3) User Contributed Perl Documentation HTTP::Config(3)
2
3
4
6 HTTP::Config - Configuration for request and response objects
7
9 use HTTP::Config;
10 my $c = HTTP::Config->new;
11 $c->add(m_domain => ".example.com", m_scheme => "http", verbose => 1);
12
13 use HTTP::Request;
14 my $request = HTTP::Request->new(GET => "http://www.example.com");
15
16 if (my @m = $c->matching($request)) {
17 print "Yadayada\n" if $m[0]->{verbose};
18 }
19
21 An "HTTP::Config" object is a list of entries that can be matched
22 against request or request/response pairs. Its purpose is to hold
23 configuration data that can be looked up given a request or response
24 object.
25
26 Each configuration entry is a hash. Some keys specify matching to
27 occur against attributes of request/response objects. Other keys can
28 be used to hold user data.
29
30 The following methods are provided:
31
32 $conf = HTTP::Config->new
33 Constructs a new empty "HTTP::Config" object and returns it.
34
35 $conf->entries
36 Returns the list of entries in the configuration object. In scalar
37 context returns the number of entries.
38
39 $conf->empty
40 Return true if there are no entries in the configuration object.
41 This is just a shorthand for "not $conf->entries".
42
43 $conf->add( %matchspec, %other )
44 $conf->add( \%entry )
45 Adds a new entry to the configuration. You can either pass
46 separate key/value pairs or a hash reference.
47
48 $conf->remove( %spec )
49 Removes (and returns) the entries that have matches for all the
50 key/value pairs in %spec. If %spec is empty this will match all
51 entries; so it will empty the configuation object.
52
53 $conf->matching( $uri, $request, $response )
54 $conf->matching( $uri )
55 $conf->matching( $request )
56 $conf->matching( $response )
57 Returns the entries that match the given $uri, $request and
58 $response triplet.
59
60 If called with a single $request object then the $uri is obtained
61 by calling its 'uri_canonical' method. If called with a single
62 $response object, then the request object is obtained by calling
63 its 'request' method; and then the $uri is obtained as if a single
64 $request was provided.
65
66 The entries are returned with the most specific matches first. In
67 scalar context returns the most specific match or "undef" in none
68 match.
69
70 $conf->add_item( $item, %matchspec )
71 $conf->remove_items( %spec )
72 $conf->matching_items( $uri, $request, $response )
73 Wrappers that hides the entries themselves.
74
75 Matching
76 The following keys on a configuration entry specify matching. For all
77 of these you can provide an array of values instead of a single value.
78 The entry matches if at least one of the values in the array matches.
79
80 Entries that require match against a response object attribute will
81 never match unless a response object was provided.
82
83 m_scheme => $scheme
84 Matches if the URI uses the specified scheme; e.g. "http".
85
86 m_secure => $bool
87 If $bool is TRUE; matches if the URI uses a secure scheme. If
88 $bool is FALSE; matches if the URI does not use a secure scheme.
89 An example of a secure scheme is "https".
90
91 m_host_port => "$hostname:$port"
92 Matches if the URI's host_port method return the specified value.
93
94 m_host => $hostname
95 Matches if the URI's host method returns the specified value.
96
97 m_port => $port
98 Matches if the URI's port method returns the specified value.
99
100 m_domain => ".$domain"
101 Matches if the URI's host method return a value that within the
102 given domain. The hostname "www.example.com" will for instance
103 match the domain ".com".
104
105 m_path => $path
106 Matches if the URI's path method returns the specified value.
107
108 m_path_prefix => $path
109 Matches if the URI's path is the specified path or has the
110 specified path as prefix.
111
112 m_path_match => $Regexp
113 Matches if the regular expression matches the URI's path. Eg.
114 qr/\.html$/.
115
116 m_method => $method
117 Matches if the request method matches the specified value. Eg.
118 "GET" or "POST".
119
120 m_code => $digit
121 m_code => $status_code
122 Matches if the response status code matches. If a single digit is
123 specified; matches for all response status codes beginning with
124 that digit.
125
126 m_proxy => $url
127 Matches if the request is to be sent to the given Proxy server.
128
129 m_media_type => "*/*"
130 m_media_type => "text/*"
131 m_media_type => "html"
132 m_media_type => "xhtml"
133 m_media_type => "text/html"
134 Matches if the response media type matches.
135
136 With a value of "html" matches if $response->content_is_html
137 returns TRUE. With a value of "xhtml" matches if
138 $response->content_is_xhtml returns TRUE.
139
140 m_uri__$method => undef
141 Matches if the URI object provides the method.
142
143 m_uri__$method => $string
144 Matches if the URI's $method method returns the given value.
145
146 m_header__$field => $string
147 Matches if either the request or the response have a header $field
148 with the given value.
149
150 m_response_attr__$key => undef
151 m_response_attr__$key => $string
152 Matches if the response object has that key, or the entry has the
153 given value.
154
156 URI, HTTP::Request, HTTP::Response
157
159 Copyright 2008, Gisle Aas
160
161 This library is free software; you can redistribute it and/or modify it
162 under the same terms as Perl itself.
163
164
165
166perl v5.12.4 2010-05-05 HTTP::Config(3)