.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "HTTP::Config 3pm" .TH HTTP::Config 3pm "2018-06-06" "perl v5.26.2" "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 "NAME" HTTP::Config \- Configuration for request and response objects .SH "VERSION" .IX Header "VERSION" version 6.18 .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 \s-1URI\s0 uses the specified scheme; e.g. \*(L"http\*(R". .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 \s-1TRUE\s0; matches if the \s-1URI\s0 uses a secure scheme. If \f(CW$bool\fR is \s-1FALSE\s0; matches if the \s-1URI\s0 does not use a secure scheme. An example of a secure scheme is \*(L"https\*(R". .ie n .IP "m_host_port => ""$hostname:$port""" 4 .el .IP "m_host_port => ``$hostname:$port''" 4 .IX Item "m_host_port => $hostname:$port" Matches if the \s-1URI\s0'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 \s-1URI\s0'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 \s-1URI\s0's port method returns the specified value. .ie n .IP "m_domain => "".$domain""" 4 .el .IP "m_domain => ``.$domain''" 4 .IX Item "m_domain => .$domain" Matches if the \s-1URI\s0's host method return a value that within the given domain. The hostname \*(L"www.example.com\*(R" will for instance match the domain \*(L".com\*(R". .ie n .IP "m_path => $path" 4 .el .IP "m_path => \f(CW$path\fR" 4 .IX Item "m_path => $path" Matches if the \s-1URI\s0'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 \s-1URI\s0'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 \s-1URI\s0'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. \*(L"\s-1GET\*(R"\s0 or \*(L"\s-1POST\*(R".\s0 .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. .ie n .IP "m_media_type => ""*/*""" 4 .el .IP "m_media_type => ``*/*''" 4 .IX Item "m_media_type => */*" .PD 0 .ie n .IP "m_media_type => ""text/*""" 4 .el .IP "m_media_type => ``text/*''" 4 .IX Item "m_media_type => text/*" .ie n .IP "m_media_type => ""html""" 4 .el .IP "m_media_type => ``html''" 4 .IX Item "m_media_type => html" .ie n .IP "m_media_type => ""xhtml""" 4 .el .IP "m_media_type => ``xhtml''" 4 .IX Item "m_media_type => xhtml" .ie n .IP "m_media_type => ""text/html""" 4 .el .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 \*(L"html\*(R" matches if \f(CW$response\fR\->content_is_html returns \s-1TRUE.\s0 With a value of \*(L"xhtml\*(R" matches if \f(CW$response\fR\->content_is_xhtml returns \s-1TRUE.\s0 .IP "m_uri_\|_\fI\f(CI$method\fI\fR => undef" 4 .IX Item "m_uri__$method => undef" Matches if the \s-1URI\s0 object provides the method. .ie n .IP "m_uri_\|_\fI\f(CI$method\fI\fR => $string" 4 .el .IP "m_uri_\|_\fI\f(CI$method\fI\fR => \f(CW$string\fR" 4 .IX Item "m_uri__$method => $string" Matches if the \s-1URI\s0's \f(CW$method\fR method returns the given value. .ie n .IP "m_header_\|_\fI\f(CI$field\fI\fR => $string" 4 .el .IP "m_header_\|_\fI\f(CI$field\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. .IP "m_response_attr_\|_\fI\f(CI$key\fI\fR => undef" 4 .IX Item "m_response_attr__$key => undef" .PD 0 .ie n .IP "m_response_attr_\|_\fI\f(CI$key\fI\fR => $string" 4 .el .IP "m_response_attr_\|_\fI\f(CI$key\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" \&\s-1URI\s0, HTTP::Request, HTTP::Response .SH "AUTHOR" .IX Header "AUTHOR" Gisle Aas .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 1994\-2017 by Gisle Aas. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.