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