HTTP::Config(3) User Contributed Perl Documentation HTTP::Config(3)

# [SYNOPSIS](#SYNOPSIS)

```
 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\n" if $m[0]->{verbose};
 }
```

# [DESCRIPTION](#DESCRIPTION)

An "HTTP::Config" 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.

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.

The following methods are provided:

$conf = HTTP::Config-&gt;new

Constructs a new empty "HTTP::Config" object and returns it.

$conf-&gt;entries

Returns the list of entries in the configuration object. In scalar context returns the number of entries.

$conf-&gt;empty

Return true if there are no entries in the configuration object. This is just a shorthand for "not $conf-&gt;entries".

$conf-&gt;add( %matchspec, %other )

$conf-&gt;add( \\%entry )

Adds a new entry to the configuration. You can either pass separate key/value pairs or a hash reference.

$conf-&gt;remove( %spec )

Removes (and returns) the entries that have matches for all the key/value pairs in %spec. If %spec is empty this will match all entries; so it will empty the configuration object.

$conf-&gt;matching( $uri, $request, $response )

$conf-&gt;matching( $uri )

$conf-&gt;matching( $request )

$conf-&gt;matching( $response )

Returns the entries that match the given $uri, $request and $response triplet.

If called with a single $request object then the $uri is obtained by calling its 'uri\_canonical' method. If called with a single $response object, then the request object is obtained by calling its 'request' method; and then the $uri is obtained as if a single $request was provided.

The entries are returned with the most specific matches first. In scalar context returns the most specific match or "undef" in none match.

$conf-&gt;add\_item( $item, %matchspec )

$conf-&gt;remove\_items( %spec )

$conf-&gt;matching\_items( $uri, $request, $response )

Wrappers that hides the entries themselves.

## [Matching](#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.

Entries that require match against a response object attribute will never match unless a response object was provided.

[m\_scheme =&gt; $scheme](#m_scheme)

Matches if the URI uses the specified scheme; e.g. "http".

[m\_secure =&gt; $bool](#m_secure)

If $bool is TRUE; matches if the URI uses a secure scheme. If $bool is FALSE; matches if the URI does not use a secure scheme. An example of a secure scheme is "https".

[m\_host\_port =&gt; "$hostname:$port"](#m_host_port)

Matches if the URI's host\_port method return the specified value.

[m\_host =&gt; $hostname](#m_host)

Matches if the URI's host method returns the specified value.

[m\_port =&gt; $port](#m_port)

Matches if the URI's port method returns the specified value.

[m\_domain =&gt; ".$domain"](#m_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".

[m\_path =&gt; $path](#m_path)

Matches if the URI's path method returns the specified value.

[m\_path\_prefix =&gt; $path](#m_path_prefix)

Matches if the URI's path is the specified path or has the specified path as prefix.

[m\_path\_match =&gt; $Regexp](#m_path_match)

Matches if the regular expression matches the URI's path. Eg. qr/\\.html$/.

[m\_method =&gt; $method](#m_method)

Matches if the request method matches the specified value. Eg. "GET" or "POST".

[m\_code =&gt; $digit](#m_code)

[m\_code =&gt; $status\_code](#m_code~2)

Matches if the response status code matches. If a single digit is specified; matches for all response status codes beginning with that digit.

[m\_proxy =&gt; $url](#m_proxy)

Matches if the request is to be sent to the given Proxy server.

[m\_media\_type =&gt; "\*/\*"](#m_media_type)

[m\_media\_type =&gt; "text/\*"](#m_media_type~2)

[m\_media\_type =&gt; "html"](#m_media_type~3)

[m\_media\_type =&gt; "xhtml"](#m_media_type~4)

[m\_media\_type =&gt; "text/html"](#m_media_type~5)

Matches if the response media type matches.

With a value of "html" matches if $response-&gt;content\_is\_html returns TRUE. With a value of "xhtml" matches if $response-&gt;content\_is\_xhtml returns TRUE.

[m\_uri\_\_*$method* =&gt; undef](#m_uri_)

Matches if the URI object provides the method.

[m\_uri\_\_*$method* =&gt; $string](#m_uri_~2)

Matches if the URI's $method method returns the given value.

[m\_header\_\_*$field* =&gt; $string](#m_header_)

Matches if either the request or the response have a header $field with the given value.

[m\_response\_attr\_\_*$key* =&gt; undef](#m_response_attr_)

[m\_response\_attr\_\_*$key* =&gt; $string](#m_response_attr_~2)

Matches if the response object has that key, or the entry has the given value.

# [SEE ALSO](#SEE_ALSO)

URI, HTTP::Request, HTTP::Response

2026-10-25 perl v5.44.0

---

Document: HTTP::Config(3pm) from perl-http-message 7.04-r1 (Chainguard OS)
Source: https://github.com/libwww-perl/HTTP-Message.git
