APR::HTTP::Headers::Compat - Make an APR::Table look like an HTTP::Headers
This document describes APR::HTTP::Headers::Compat version 0.02
use APR::HTTP::Headers::Compat; # We're running under mod_perl2... my $hdrs = APR::HTTP::Headers::Compat->new( $r->headers_out ); # Now we can treat $hdrs as if it was an HTTP::Headers $hdrs->header( 'Content-Type' => 'text/plain' );
Under mod_perl HTTP headers are stashed in APR::Table objects. Sometimes you will encounter code (such as FirePHP::Dispatcher) that needs an HTTP::Headers. This module wraps an APR::Table in a subclass of HTTP::Headers so that it can be used wherever an HTTP::Headers is expected.
APR::Table
HTTP::Headers
Synchronisation is bi-directional; changes via the HTTP::Headers interface are reflected immediately in the underlying APR::Table and direct changes to the table show up immediately in the wrapper.
Unless otherwise stated below all methods are inherited from HTTP::Headers.
new
Create a new wrapper around an existing APR::Table.
# Normally you'll be given the table - we're creating one here for the # sake of the example my $table = APR::Table::make( APR::Pool->new, 1 ); # Wrap the table so it can be used as an HTTP::Headers instance my $h = APR::HTTP::Headers::Compat->new( $table );
Optionally header initialisers may be passed:
my $h = APR::HTTP::Headers::Compat->new( $table, 'Content-type' => 'text/plain' );
clone
Clone this object. The clone is a regular HTTP::Headers object rather than an APR::HTTP::Headers::Compat.
APR::HTTP::Headers::Compat
table
Get the underlying APR::Table object. Changes made in either the table or the wrapper are reflected immediately in the other.
remove_content_headers
This will remove all the header fields used to describe the content of a message. All header field names prefixed with Content- falls into this category, as well as Allow, Expires and Last-Modified. RFC 2616 denote these fields as Entity Header Fields.
The return value is a new HTTP::Headers object that contains the removed headers only. Note that the returned object is not an APR::HTTP::Headers::Compat.
Because the underlying storage for the headers is an APR::Table attempts to store an object (such as a URI instance) in the table will not behave as expected.
I haven't benchmarked but it's certain that this implementation will be substantially slower than HTTP::Headers.
APR::Pool, APR::Table, HTTP::Headers, Storable, Test::More
FirePHP::Dispatcher
None reported.
Please report any bugs or feature requests to bug-apr-http-headers-compat@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-apr-http-headers-compat@rt.cpan.org
Andy Armstrong <andy@hexten.net>
<andy@hexten.net>
Copyright (c) 2009, Andy Armstrong <andy@hexten.net>.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install APR::HTTP::Headers::Compat, copy and paste the appropriate command in to your terminal.
cpanm
cpanm APR::HTTP::Headers::Compat
CPAN shell
perl -MCPAN -e shell install APR::HTTP::Headers::Compat
For more information on module installation, please visit the detailed CPAN module installation guide.