| APR-HTTP-Headers-Compat documentation | Contained in the APR-HTTP-Headers-Compat distribution. |
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.
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.
newCreate 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'
);
cloneClone this object. The clone is a regular HTTP::Headers object rather
than an APR::HTTP::Headers::Compat.
tableGet the underlying APR::Table object. Changes made in either the table or the wrapper are reflected immediately in the other.
remove_content_headersThis 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.
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.
Andy Armstrong <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.
| APR-HTTP-Headers-Compat documentation | Contained in the APR-HTTP-Headers-Compat distribution. |
package APR::HTTP::Headers::Compat; use warnings; use strict; use Carp; use APR::HTTP::Headers::Compat::MagicHash; use base qw( HTTP::Headers );
our $VERSION = '0.02';
sub new { my ( $class, $table ) = ( shift, shift ); my %self = %{ $class->SUPER::new( @_ ) }; tie %self, 'APR::HTTP::Headers::Compat::MagicHash', $table, %self; return bless \%self, $class; } sub _magic { tied %{ shift() } }
sub clone { bless { %{ shift() } }, 'HTTP::Headers' }
sub table { shift->_magic->table }
sub remove_content_headers { my $self = shift; return $self->SUPER::remove_content_headers( @_ ) unless defined wantarray; # This gets nasty. We downbless ourself to be an HTTP::Headers so that # when HTTP::Headers->remove_content_headers does # # my $c = ref( $self )->new # # it creates a new HTTP::Headers instead of attempting to create a # new APR::HTTP::Headers::Compat. my $class = ref $self; bless $self, 'HTTP::Headers'; # Calls SUPER::remove_content_headers due to rebless my $other = $self->remove_content_headers( @_ ); bless $self, $class; # Return a non-magic HTTP::Headers return $other; } 1; __END__