HTTP::Config(3)

πŸ’– HTTP::Config β€” bestie edition πŸ’–

okay so this is a User Contributed Perl Documentation page, and it's about HTTP::Config, aka the little config brain that holds a whole list of entries you can match against request objects (or request + response pairs). it's giving "lookup table but make it ✨vibes✨". no cap, it's genuinely useful.


✨ NAME ✨

HTTP::Config β€” configuration for request and response objects πŸŽ€


🌸 VERSION 🌸

this is version 7.03, periodt.


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the whole flex, verbatim, no notes:

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};
}

like... you build a config, you add an entry with a match spec, you throw a request at it, and you get your matching entries back. main character energy fr fr. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so an HTTP::Config object is literally just a list of entries that can be matched against request objects, or against request/response pairs. its whole purpose in life is to hold configuration data that you can look up later, given a request or a response object. iconic behaviour honestly.

each configuration entry is a hash. some keys specify matching to occur against attributes of request/response objects (those are the m_ ones, iykyk). other keys can be used to hold your own user data β€” go off, put whatever you want in there. 🫢

the following methods are provided:

  • $conf = HTTP::Config->new β€” constructs a new empty HTTP::Config object and returns it. baby's first config. πŸ‘‘
  • $conf->entries β€” returns the list of entries in the configuration object. in scalar context it returns the number of entries. she's flexible like that.
  • $conf->empty β€” returns true if there are no entries in the configuration object. this is just a shorthand for not $conf->entries. lowkey just a vibe check on your config.
  • $conf->add( %matchspec, %other ) $conf->add( \%entry ) β€” adds a new entry to the configuration. you can either pass separate key/value pairs or a hash reference. either way, slay.
  • $conf->remove( %spec ) β€” removes (and returns) the entries that have matches for all the key/value pairs in %spec. ⚠️ heads up bestie: if %spec is empty this will match all entries, so it will empty the configuration object entirely. that's a full reset, no undo. πŸ’€
  • $conf->matching( $uri, $request, $response ) $conf->matching( $uri ) $conf->matching( $request ) $conf->matching( $response ) β€” returns the entries that match the given $uri, $request and $response triplet.

if you call it with a single $request object, then the $uri is obtained by calling its 'uri_canonical' method. if you call it 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. it just figures it out for you, honestly so thoughtful.

the entries are returned with the most specific matches first. in scalar context it returns the most specific match, or undef if none match. 😭

  • $conf->add_item( $item, %matchspec ) $conf->remove_items( %spec ) $conf->matching_items( $uri, $request, $response ) β€” wrappers that hide the entries themselves. shy girlies.

πŸ” 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 β€” and the entry matches if at least one of the values in the array matches. so generous.

⚠️ important: entries that require a match against a response object attribute will never match unless a response object was provided. she can't read what you didn't hand her. πŸ™ˆ
  • m_scheme => $scheme β€” matches if the URI uses the specified scheme; e.g. "http".
  • m_secure => $bool β€” 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". secure queen behavior πŸ”’
  • m_host_port => "$hostname:$port" β€” matches if the URI's host_port method returns the specified value.
  • m_host => $hostname β€” matches if the URI's host method returns the specified value.
  • m_port => $port β€” matches if the URI's port method returns the specified value.
  • m_domain => ".$domain" β€” matches if the URI's host method returns a value that's within the given domain. the hostname www.example.com will for instance match the domain ".com". so broad, so powerful.
  • m_path => $path β€” matches if the URI's path method returns the specified value.
  • m_path_prefix => $path β€” matches if the URI's path is the specified path or has the specified path as a prefix.
  • m_path_match => $Regexp β€” matches if the regular expression matches the URI's path. eg. qr/\.html$/. regex girlies rise up ✨
  • m_method => $method β€” matches if the request method matches the specified value. eg. "GET" or "POST".
  • m_code => $digit m_code => $status_code β€” matches if the response status code matches. if a single digit is specified, it matches for all response status codes beginning with that digit. like a little wildcard, cute.
  • m_proxy => $url β€” matches if the request is to be sent to the given Proxy server.
  • m_media_type => "*/*" m_media_type => "text/*" m_media_type => "html" m_media_type => "xhtml" m_media_type => "text/html" β€” matches if the response media type matches.

with a value of "html" it matches if $response->content_is_html returns TRUE. with a value of "xhtml" it matches if $response->content_is_xhtml returns TRUE. those two are the special little stars of the group. ⭐

  • m_uri__$method => undef β€” matches if the URI object provides the method.
  • m_uri__$method => $string β€” matches if the URI's $method method returns the given value.
  • m_header__$field => $string β€” matches if either the request or the response have a header $field with the given value.
  • m_response_attr__$key => undef m_response_attr__$key => $string β€” matches if the response object has that key, or if the entry has the given value.

🌈 SEE ALSO 🌈

URI, HTTP::Request, HTTP::Response β€” go read those next bestie, they're the whole friend group πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

Gisle Aas <gisle@activestate.com> β€” thank you for your service, king 🫑


this software is copyright (c) 1994 by Gisle Aas.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so yes, you may absolutely do whatever, legally. slay.


and that's the whole page! πŸŽ€ just so you know where this all came from: this ships with perl v5.42.2 and the page is dated 2026-07-23 β€” that's the HTTP::Config(3) manual, bestie. go forth and configure. βœ¨πŸ¦‹πŸ’…

πŸ“¦ where this page comes from