HTTP::...rFilter(3pm)
β¨ NAME β¨
HTTP::Proxy::HeaderFilter β bestie, it's literally a base class for HTTP message header filters π
(that's the HTTP::...rFilter(3pm) you clicked on, from the User Contributed Perl Documentation manual, no cap)
πΈ SYNOPSIS πΈ
package MyFilter;
use base qw( HTTP::Proxy::HeaderFilter );
# changes the User-Agent header in all requests
# this filter must be pushed on the request stack
sub filter {
my ( $self, $headers, $message ) = @_;
$message->headers->header( User_Agent => 'MyFilter/1.0' );
}
1;
π¦ DESCRIPTION π¦
okay so listen. The HTTP::Proxy::HeaderFilter class is the blueprint you use to build filters that mess with HTTP request/response headers. That's the whole vibe. π
π Creating a HeaderFilter
A HeaderFilter is just a derived class (yes, a subclass, we're being fancy) that implements a couple of methods the proxy calls on its own. And of all the methods listed down here, literally only filter() has to be defined in your derived class. The rest are optional, so breathe. π«Ά
filter()
The signature of the filter() method is exactly this, character for character:
sub filter { my ( $self, $headers, $message) = @_; ... }
where $self is the filter object, $headers is a HTTP::Headers object, and $message is either a HTTP::Request or a HTTP::Response object. Three args, that's it, slay. β¨
The $headers HTTP::Headers object is the one that will actually get sent to the client (if your filter is sitting on the response stack) or to the origin server (if your filter is on the request stack). And if your filter modifies $headers, then the modified headers are what get sent to the client or the server. So likeβ¦ you change it, it ships. That's the power. π
The init() method (if it exists) is called by the new() constructeur to do all the initisalisation tasks. It gets called once in the filter lifetime. One time. That's it. π
A HTTP::Proxy::HeaderFilter object is a blessed hash, and the base class reserves only hash keys that start with "_hphf". So don't touch those, bestie, they're not yours. π
new()
The constructor is defined for all subclasses β you don't write it, it's already there. Any initialisation tasks your subclass needs (if any) go in the init() method instead (peep below π).
init()
This method is called by the new() constructeur to perform all the initisalisation tasks. It's called once in the filter lifetime. β
It receives all the parameters passed to new(). All of them. Every single one. π«Ά
π Standard HeaderFilters
Standard HTTP::Proxy::HeaderFilter classes are lowercase. (iykyk, it's a naming convention thing.)
The following HeaderFilters are included in the HTTP::Proxy distribution:
simpleβ this class lets you create a simple header filter from a code reference. Iconic, low effort, big results. β¨standardβ this is the filter that provides standard headers handling forHTTP::Proxy. It gets loaded automatically byHTTP::Proxy, so you don't even have to do anything. Main character energy fr fr. π
Please read each filter's documentation for more details about their use. (Do it. Go read it. I'll wait. π)
π USEFUL METHODS FOR SUBCLASSES π
Some methods are available to filters, so they can eventually use the little knowledge they might have of HTTP::Proxy's internals. They're mostly accessors. Lowkey handy.
proxy()
Gets a reference to the HTTP::Proxy object that owns the filter. This gives you access to some of the proxy methods. It's giving "backstage pass". ποΈ
π AUTHOR π
Philippe "BooK" Bruhat, <book@cpan.org>. A legend. We stan. π
π§ SEE ALSO π§
HTTP::ProxyHTTP::Proxy::BodyFilter
π COPYRIGHT π
Copyright 2003-2015, Philippe Bruhat.
β LICENSE β
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
perl v5.36.0 Β· 2022-12-04 Β· HTTP::...rFilter(3pm) β that's a wrap bestie, go build some filters, you're gonna eat π
β¨π¦
π¦ where this page comes from
- debian bookworm: libhttp-proxy-perl 0.304-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhttp-proxy-perl 0.304-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhttp-proxy-perl 0.304-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms