Net::Inspect::L7::HTTP::Request::InspectChain - chained inspection and modification of HTTP request and response
With this class one can deeply analyze and modify a HTTP request, like unchunking and uncompressing the content and adding custom functions to modify request and response header and content.
It provides all hooks required from Net::Inspect::L7::HTTP
and will require the same hooks for the attached upper flow,
which will receive the modified header and content.
The following methods are provided for adding inspection and modification:
adds the given inspection/modification hooks.
A hook is either a string for predefined hooks or a hash ref with the name of the hookable place as key and a code ref or array-ref with code-ref and arguments implementing the hook as the value.
The key 'name' can be used to give the hook a name,
which later can be used in update_hook
.
The hooks will be applied in the given order.
With pos
the position in the list can be defined,
e.g.
0 will insert at the beginning,
undef will add at the end.
Adding at the end is the default.
Note that the order of the hooks is really important!
Option keys in %opt
start with '-'.
All options will be added to the following hooks.
The following hookable places exist and require the given kind of hook code:
This hook is called after reading the request header.
The header as a string is given as a scalar-ref and can be modified.
Using request_header
method the header can be accessed as HTTP::Request object.
The hook should return 1 if the header was changed and 0 if not.
If it returns undef the processing will stop and it will be expected,
that the hook already called $self->fatal
in this case to propagate the error.
This hook is called whenever new data arrive for the request body.
It should modify $data
to remove all processed content and returns the processed content.
If content remains in $data
it will be still in it when the hook is called again when new data arrive.
This means especially,
that nothing should remain in $data
if $eof
is true,
because no more data will arrive.
If this condition is not met the code will die()
.
This is similar to request_header
,
except that is applied to the response header.
This is similar to request_body
,
except that is applied to the response body.
It will only be called on the content,
not on the framing of chunked encoding.
This will be called for each header of the framing in chunked encoding.
One can modify $hdr
.
The hook should return undef on error,
otherwise something defined.
This will be called for the trailer of the framing in chunked encoding.
One can modify $trailer
.
The hook should return undef on error,
otherwise something defined.
The following predefined hooks exist:
will hook into response_header
.
If it says,
that the response is chunked it will remove the chunked info from Transfer-Encoding
header and update hooks in chunk_header
and chunk_trailer
to remove the chunk framing.
If the chunking was found and removed it will set $self-
{info}{chunked}>.
If option -original-header-prefix
is given it will preserver the original header for alle changed headers with the given prefix.
will hook into response_header
.
If it says,
that the response has a Content-Encoding
of gzip or inflate it will remove the info from the header and update hook in response_body
to uncompress content.
If compression was found and removed it will set $self-
{info}{ce_gzip}> or $self-
{info}{ce_inflate}>.
If option -original-header-prefix
is given it will preserver the original header for alle changed headers with the given prefix.
same as uncompress_ce,
but for Transfer-Encoding
.
will update the hook with with name $name
with the given definition.
Hookable places not given in %hook
will be kept.
helper function which will return HTTP::Request object for the request header. Can also be used to set new header.
helper function which will return HTTP::Response object for the response header Can also be used to set new header.
Only gzip and inflate are supported for uncompression, no 'uncompress'