perl – mod_perl headers_in not working – Education Career Blog

I’m using mod_perl 2 with Apache 2.2.3 on Red Hat 5.2, and I’m trying to access the request headers, but the Apache2::RequestRec headers_in method (or rather, its return value) is not behaving the way I would expect.

Code fragment:

$logger->warn('version ' . $mod_perl::VERSION);
$logger->warn('r ' . $r);
my $headers = $r->headers_in;
$logger->warn('headers ' . $headers);
my $accept = $headers->get('Accept');
$logger->warn('got $accept');

gives the following log output:

WARN version 2.000004
WARN r Apache2::RequestRec=SCALAR(0x2ae0598e9ef0)
WARN headers APR::Table=HASH(0x2ae06cad15a0)

with execution appearing to halt as soon as any access to the APR::Table is attempted.
The tied interface for APR::Table had the same effect – i.e. changing the get('Accept') line to:

my $accept = $headers->{Accept};

gives exactly the same log output.

According to the above linked documentation:

This table is available starting from the PerlHeaderParserHandler phase

So I would expect my code, running in the PerlResponseHandler phase, to be able to access the headers.

Does anyone have any ideas what I’m doing wrong?

Edit: Using Data::Dumper hasn’t really clarified matters at all.


use Data::Dumper;
my $headers = $r->headers_in;
$logger->warn('have dumped $headers');


WARN $VAR1 = bless( do{\(my $o = '47143456365192')}, 'Apache2::RequestRec' );

WARN APR::Table=HASH(0x2ae071b06fd0)

So it seems that trying to get into $headers even through Data::Dumper results in the execution halting.

Edit: Attempting to set one of the headers fails as well.

$logger->warn('reset accept');
$r->headers_in->{'Accept'}= 'everything';
$logger->warn('post set accept');

stops log output at the

WARN reset accept

point. I tried the set(Accept => 'everything') alternative as well, with the same result.


Is there anything in the apache logs? It seems if your code stops executing there should be an error somewhere saying why.


Problem found:

I needed to add

use APR::Table;

somewhere. Kind of weird that it was happily able to create an APR::Table object though.


Have you tried getting the Accept header without assigning the header object to $header:

my $accept = $r->headers_in->get('Accept');

This works in my code running in the PerlResponseHandler phase.

Leave a Comment