.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTTP::Config 3" .TH HTTP::Config 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 3 \& use HTTP::Config; \& my $c = HTTP::Config\->new; \& $c\->add(m_domain => ".example.com", m_scheme => "http", verbose => 1); \& \& use HTTP::Request; \& my $request = HTTP::Request\->new(GET => "http://www.example.com"); \& \& if (my @m = $c\->matching($request)) { \& print "Yadayada\en" if $m[0]\->{verbose}; \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" An \f(CW\*(C`HTTP::Config\*(C'\fR object is a list of entries that can be matched against request or request/response pairs. Its purpose is to hold configuration data that can be looked up given a request or response object. .PP Each configuration entry is a hash. Some keys specify matching to occur against attributes of request/response objects. Other keys can be used to hold user data. .PP The following methods are provided: .ie n .IP "$conf = HTTP::Config\->new" 4 .el .IP "\f(CW$conf\fR = HTTP::Config\->new" 4 .IX Item "$conf = HTTP::Config->new" Constructs a new empty \f(CW\*(C`HTTP::Config\*(C'\fR object and returns it. .ie n .IP $conf\->entries 4 .el .IP \f(CW$conf\fR\->entries 4 .IX Item "$conf->entries" Returns the list of entries in the configuration object. In scalar context returns the number of entries. .ie n .IP $conf\->empty 4 .el .IP \f(CW$conf\fR\->empty 4 .IX Item "$conf->empty" Return true if there are no entries in the configuration object. This is just a shorthand for \f(CW\*(C`not $conf\->entries\*(C'\fR. .ie n .IP "$conf\->add( %matchspec, %other )" 4 .el .IP "\f(CW$conf\fR\->add( \f(CW%matchspec\fR, \f(CW%other\fR )" 4 .IX Item "$conf->add( %matchspec, %other )" .PD 0 .ie n .IP "$conf\->add( \e%entry )" 4 .el .IP "\f(CW$conf\fR\->add( \e%entry )" 4 .IX Item "$conf->add( %entry )" .PD Adds a new entry to the configuration. You can either pass separate key/value pairs or a hash reference. .ie n .IP "$conf\->remove( %spec )" 4 .el .IP "\f(CW$conf\fR\->remove( \f(CW%spec\fR )" 4 .IX Item "$conf->remove( %spec )" Removes (and returns) the entries that have matches for all the key/value pairs in \f(CW%spec\fR. If \f(CW%spec\fR is empty this will match all entries; so it will empty the configuration object. .ie n .IP "$conf\->matching( $uri, $request, $response )" 4 .el .IP "\f(CW$conf\fR\->matching( \f(CW$uri\fR, \f(CW$request\fR, \f(CW$response\fR )" 4 .IX Item "$conf->matching( $uri, $request, $response )" .PD 0 .ie n .IP "$conf\->matching( $uri )" 4 .el .IP "\f(CW$conf\fR\->matching( \f(CW$uri\fR )" 4 .IX Item "$conf->matching( $uri )" .ie n .IP "$conf\->matching( $request )" 4 .el .IP "\f(CW$conf\fR\->matching( \f(CW$request\fR )" 4 .IX Item "$conf->matching( $request )" .ie n .IP "$conf\->matching( $response )" 4 .el .IP "\f(CW$conf\fR\->matching( \f(CW$response\fR )" 4 .IX Item "$conf->matching( $response )" .PD Returns the entries that match the given \f(CW$uri\fR, \f(CW$request\fR and \f(CW$response\fR triplet. .Sp If called with a single \f(CW$request\fR object then the \f(CW$uri\fR is obtained by calling its 'uri_canonical' method. If called with a single \f(CW$response\fR object, then the request object is obtained by calling its 'request' method; and then the \f(CW$uri\fR is obtained as if a single \f(CW$request\fR was provided. .Sp The entries are returned with the most specific matches first. In scalar context returns the most specific match or \f(CW\*(C`undef\*(C'\fR in none match. .ie n .IP "$conf\->add_item( $item, %matchspec )" 4 .el .IP "\f(CW$conf\fR\->add_item( \f(CW$item\fR, \f(CW%matchspec\fR )" 4 .IX Item "$conf->add_item( $item, %matchspec )" .PD 0 .ie n .IP "$conf\->remove_items( %spec )" 4 .el .IP "\f(CW$conf\fR\->remove_items( \f(CW%spec\fR )" 4 .IX Item "$conf->remove_items( %spec )" .ie n .IP "$conf\->matching_items( $uri, $request, $response )" 4 .el .IP "\f(CW$conf\fR\->matching_items( \f(CW$uri\fR, \f(CW$request\fR, \f(CW$response\fR )" 4 .IX Item "$conf->matching_items( $uri, $request, $response )" .PD Wrappers that hides the entries themselves. .SS Matching .IX Subsection "Matching" The following keys on a configuration entry specify matching. For all of these you can provide an array of values instead of a single value. The entry matches if at least one of the values in the array matches. .PP Entries that require match against a response object attribute will never match unless a response object was provided. .ie n .IP "m_scheme => $scheme" 4 .el .IP "m_scheme => \f(CW$scheme\fR" 4 .IX Item "m_scheme => $scheme" Matches if the URI uses the specified scheme; e.g. "http". .ie n .IP "m_secure => $bool" 4 .el .IP "m_secure => \f(CW$bool\fR" 4 .IX Item "m_secure => $bool" If \f(CW$bool\fR is TRUE; matches if the URI uses a secure scheme. If \f(CW$bool\fR is FALSE; matches if the URI does not use a secure scheme. An example of a secure scheme is "https". .IP "m_host_port => ""$hostname:$port""" 4 .IX Item "m_host_port => ""$hostname:$port""" Matches if the URI's host_port method return the specified value. .ie n .IP "m_host => $hostname" 4 .el .IP "m_host => \f(CW$hostname\fR" 4 .IX Item "m_host => $hostname" Matches if the URI's host method returns the specified value. .ie n .IP "m_port => $port" 4 .el .IP "m_port => \f(CW$port\fR" 4 .IX Item "m_port => $port" Matches if the URI's port method returns the specified value. .IP "m_domain => "".$domain""" 4 .IX Item "m_domain => "".$domain""" Matches if the URI's host method return a value that within the given domain. The hostname "www.example.com" will for instance match the domain ".com". .ie n .IP "m_path => $path" 4 .el .IP "m_path => \f(CW$path\fR" 4 .IX Item "m_path => $path" Matches if the URI's path method returns the specified value. .ie n .IP "m_path_prefix => $path" 4 .el .IP "m_path_prefix => \f(CW$path\fR" 4 .IX Item "m_path_prefix => $path" Matches if the URI's path is the specified path or has the specified path as prefix. .ie n .IP "m_path_match => $Regexp" 4 .el .IP "m_path_match => \f(CW$Regexp\fR" 4 .IX Item "m_path_match => $Regexp" Matches if the regular expression matches the URI's path. Eg. qr/\e.html$/. .ie n .IP "m_method => $method" 4 .el .IP "m_method => \f(CW$method\fR" 4 .IX Item "m_method => $method" Matches if the request method matches the specified value. Eg. "GET" or "POST". .ie n .IP "m_code => $digit" 4 .el .IP "m_code => \f(CW$digit\fR" 4 .IX Item "m_code => $digit" .PD 0 .ie n .IP "m_code => $status_code" 4 .el .IP "m_code => \f(CW$status_code\fR" 4 .IX Item "m_code => $status_code" .PD Matches if the response status code matches. If a single digit is specified; matches for all response status codes beginning with that digit. .ie n .IP "m_proxy => $url" 4 .el .IP "m_proxy => \f(CW$url\fR" 4 .IX Item "m_proxy => $url" Matches if the request is to be sent to the given Proxy server. .IP "m_media_type => ""*/*""" 4 .IX Item "m_media_type => ""*/*""" .PD 0 .IP "m_media_type => ""text/*""" 4 .IX Item "m_media_type => ""text/*""" .IP "m_media_type => ""html""" 4 .IX Item "m_media_type => ""html""" .IP "m_media_type => ""xhtml""" 4 .IX Item "m_media_type => ""xhtml""" .IP "m_media_type => ""text/html""" 4 .IX Item "m_media_type => ""text/html""" .PD Matches if the response media type matches. .Sp With a value of "html" matches if \f(CW$response\fR\->content_is_html returns TRUE. With a value of "xhtml" matches if \f(CW$response\fR\->content_is_xhtml returns TRUE. .ie n .IP "m_uri_\|_\fR\fI$method\fR\fI\fR => undef" 4 .el .IP "m_uri_\|_\fR\f(CI$method\fR\fI\fR => undef" 4 .IX Item "m_uri__$method => undef" Matches if the URI object provides the method. .ie n .IP "m_uri_\|_\fR\fI$method\fR\fI\fR => $string" 4 .el .IP "m_uri_\|_\fR\f(CI$method\fR\fI\fR => \f(CW$string\fR" 4 .IX Item "m_uri__$method => $string" Matches if the URI's \f(CW$method\fR method returns the given value. .ie n .IP "m_header_\|_\fR\fI$field\fR\fI\fR => $string" 4 .el .IP "m_header_\|_\fR\f(CI$field\fR\fI\fR => \f(CW$string\fR" 4 .IX Item "m_header__$field => $string" Matches if either the request or the response have a header \f(CW$field\fR with the given value. .ie n .IP "m_response_attr_\|_\fR\fI$key\fR\fI\fR => undef" 4 .el .IP "m_response_attr_\|_\fR\f(CI$key\fR\fI\fR => undef" 4 .IX Item "m_response_attr__$key => undef" .PD 0 .ie n .IP "m_response_attr_\|_\fR\fI$key\fR\fI\fR => $string" 4 .el .IP "m_response_attr_\|_\fR\f(CI$key\fR\fI\fR => \f(CW$string\fR" 4 .IX Item "m_response_attr__$key => $string" .PD Matches if the response object has that key, or the entry has the given value. .SH "SEE ALSO" .IX Header "SEE ALSO" URI, HTTP::Request, HTTP::Response