man-pages/man3/HTTP::Config.3pm.html
2021-03-31 01:06:50 +01:00

368 lines
8.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of HTTP::Config</TITLE>
</HEAD><BODY>
<H1>HTTP::Config</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2020-02-29<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
HTTP::Config - Configuration for request and response objects
<A NAME="lbAC">&nbsp;</A>
<H2>VERSION</H2>
version 6.22
<A NAME="lbAD">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use HTTP::Config;
my $c = HTTP::Config-&gt;new;
$c-&gt;add(m_domain =&gt; &quot;.example.com&quot;, m_scheme =&gt; &quot;http&quot;, verbose =&gt; 1);
use HTTP::Request;
my $request = HTTP::Request-&gt;new(GET =&gt; &quot;<A HREF="http://www.example.com">http://www.example.com</A>&quot;);
if (my @m = $c-&gt;matching($request)) {
print &quot;Yadayada\n&quot; if $m[0]-&gt;{verbose};
}
</PRE>
<A NAME="lbAE">&nbsp;</A>
<H2>DESCRIPTION</H2>
An <TT>&quot;HTTP::Config&quot;</TT> 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.
<P>
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.
<P>
The following methods are provided:
<DL COMPACT>
<DT id="1">$conf = HTTP::Config-&gt;new<DD>
Constructs a new empty <TT>&quot;HTTP::Config&quot;</TT> object and returns it.
<DT id="2">$conf-&gt;entries<DD>
Returns the list of entries in the configuration object.
In scalar context returns the number of entries.
<DT id="3">$conf-&gt;empty<DD>
Return true if there are no entries in the configuration object.
This is just a shorthand for <TT>&quot;not $conf-&gt;entries&quot;</TT>.
<DT id="4">$conf-&gt;add( %matchspec, %other )<DD>
<DT id="5">$conf-&gt;add( \%entry )<DD>
Adds a new entry to the configuration.
You can either pass separate key/value pairs or a hash reference.
<DT id="6">$conf-&gt;remove( %spec )<DD>
Removes (and returns) the entries that have matches for all the key/value pairs in <TT>%spec</TT>.
If <TT>%spec</TT> is empty this will match all entries; so it will empty the configuration object.
<DT id="7">$conf-&gt;matching( $uri, $request, $response )<DD>
<DT id="8">$conf-&gt;matching( $uri )<DD>
<DT id="9">$conf-&gt;matching( $request )<DD>
<DT id="10">$conf-&gt;matching( $response )<DD>
Returns the entries that match the given <TT>$uri</TT>, <TT>$request</TT> and <TT>$response</TT> triplet.
<P>
If called with a single <TT>$request</TT> object then the <TT>$uri</TT> is obtained by calling its 'uri_canonical' method.
If called with a single <TT>$response</TT> object, then the request object is obtained by calling its 'request' method;
and then the <TT>$uri</TT> is obtained as if a single <TT>$request</TT> was provided.
<P>
The entries are returned with the most specific matches first.
In scalar context returns the most specific match or <TT>&quot;undef&quot;</TT> in none match.
<DT id="11">$conf-&gt;add_item( $item, %matchspec )<DD>
<DT id="12">$conf-&gt;remove_items( %spec )<DD>
<DT id="13">$conf-&gt;matching_items( $uri, $request, $response )<DD>
Wrappers that hides the entries themselves.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H3>Matching</H3>
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.
<P>
Entries that require match against a response object attribute will never match
unless a response object was provided.
<DL COMPACT>
<DT id="14">m_scheme =&gt; $scheme<DD>
Matches if the <FONT SIZE="-1">URI</FONT> uses the specified scheme; e.g. ``http''.
<DT id="15">m_secure =&gt; $bool<DD>
If <TT>$bool</TT> is <FONT SIZE="-1">TRUE</FONT>; matches if the <FONT SIZE="-1">URI</FONT> uses a secure scheme. If <TT>$bool</TT>
is <FONT SIZE="-1">FALSE</FONT>; matches if the <FONT SIZE="-1">URI</FONT> does not use a secure scheme. An example
of a secure scheme is ``https''.
<DT id="16">m_host_port =&gt; &quot;$hostname:$port&quot;<DD>
Matches if the <FONT SIZE="-1">URI</FONT>'s host_port method return the specified value.
<DT id="17">m_host =&gt; $hostname<DD>
Matches if the <FONT SIZE="-1">URI</FONT>'s host method returns the specified value.
<DT id="18">m_port =&gt; $port<DD>
Matches if the <FONT SIZE="-1">URI</FONT>'s port method returns the specified value.
<DT id="19">m_domain =&gt; &quot;.$domain&quot;<DD>
Matches if the <FONT SIZE="-1">URI</FONT>'s host method return a value that within the given
domain. The hostname ``<A HREF="http://www.example.com">www.example.com</A>'' will for instance match the
domain ``.com''.
<DT id="20">m_path =&gt; $path<DD>
Matches if the <FONT SIZE="-1">URI</FONT>'s path method returns the specified value.
<DT id="21">m_path_prefix =&gt; $path<DD>
Matches if the <FONT SIZE="-1">URI</FONT>'s path is the specified path or has the specified
path as prefix.
<DT id="22">m_path_match =&gt; $Regexp<DD>
Matches if the regular expression matches the <FONT SIZE="-1">URI</FONT>'s path. Eg. qr/\.html$/.
<DT id="23">m_method =&gt; $method<DD>
Matches if the request method matches the specified value. Eg. ``<FONT SIZE="-1">GET''</FONT> or ``<FONT SIZE="-1">POST''.</FONT>
<DT id="24">m_code =&gt; $digit<DD>
<DT id="25">m_code =&gt; $status_code<DD>
Matches if the response status code matches. If a single digit is
specified; matches for all response status codes beginning with that digit.
<DT id="26">m_proxy =&gt; $url<DD>
Matches if the request is to be sent to the given Proxy server.
<DT id="27">m_media_type =&gt; &quot;*/*&quot;<DD>
<DT id="28">m_media_type =&gt; &quot;text/*&quot;<DD>
<DT id="29">m_media_type =&gt; &quot;html&quot;<DD>
<DT id="30">m_media_type =&gt; &quot;xhtml&quot;<DD>
<DT id="31">m_media_type =&gt; &quot;text/html&quot;<DD>
Matches if the response media type matches.
<P>
With a value of ``html'' matches if <TT>$response</TT>-&gt;content_is_html returns <FONT SIZE="-1">TRUE.</FONT>
With a value of ``xhtml'' matches if <TT>$response</TT>-&gt;content_is_xhtml returns <FONT SIZE="-1">TRUE.</FONT>
<DT id="32">m_uri__<I></I>$method<I></I> =&gt; undef<DD>
Matches if the <FONT SIZE="-1">URI</FONT> object provides the method.
<DT id="33">m_uri__<I></I>$method<I></I> =&gt; $string<DD>
Matches if the <FONT SIZE="-1">URI</FONT>'s <TT>$method</TT> method returns the given value.
<DT id="34">m_header__<I></I>$field<I></I> =&gt; $string<DD>
Matches if either the request or the response have a header <TT>$field</TT> with the given value.
<DT id="35">m_response_attr__<I></I>$key<I></I> =&gt; undef<DD>
<DT id="36">m_response_attr__<I></I>$key<I></I> =&gt; $string<DD>
Matches if the response object has that key, or the entry has the given value.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>SEE ALSO</H2>
<FONT SIZE="-1">URI</FONT>, HTTP::Request, HTTP::Response
<A NAME="lbAH">&nbsp;</A>
<H2>AUTHOR</H2>
Gisle Aas &lt;<A HREF="mailto:gisle@activestate.com">gisle@activestate.com</A>&gt;
<A NAME="lbAI">&nbsp;</A>
<H2>COPYRIGHT AND LICENSE</H2>
This software is copyright (c) 1994-2017 by Gisle Aas.
<P>
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="37"><A HREF="#lbAB">NAME</A><DD>
<DT id="38"><A HREF="#lbAC">VERSION</A><DD>
<DT id="39"><A HREF="#lbAD">SYNOPSIS</A><DD>
<DT id="40"><A HREF="#lbAE">DESCRIPTION</A><DD>
<DL>
<DT id="41"><A HREF="#lbAF">Matching</A><DD>
</DL>
<DT id="42"><A HREF="#lbAG">SEE ALSO</A><DD>
<DT id="43"><A HREF="#lbAH">AUTHOR</A><DD>
<DT id="44"><A HREF="#lbAI">COPYRIGHT AND LICENSE</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:45 GMT, March 31, 2021
</BODY>
</HTML>