Note that there are some explanatory texts on larger screens.

plurals
  1. POmod_perl headers_in not working
    primarykey
    data
    text
    <p>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 <a href="http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_headers_in_" rel="nofollow noreferrer">headers_in</a> method (or rather, its return value) is not behaving the way I would expect.</p> <p>Code fragment:</p> <pre><code>$logger-&gt;warn('version ' . $mod_perl::VERSION); $logger-&gt;warn('r ' . $r); my $headers = $r-&gt;headers_in; $logger-&gt;warn('headers ' . $headers); my $accept = $headers-&gt;get('Accept'); $logger-&gt;warn('got $accept'); $logger-&gt;warn($accept); </code></pre> <p>gives the following log output:</p> <pre><code>WARN version 2.000004 WARN r Apache2::RequestRec=SCALAR(0x2ae0598e9ef0) WARN headers APR::Table=HASH(0x2ae06cad15a0) </code></pre> <p>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 <code>get('Accept')</code> line to:</p> <pre><code>my $accept = $headers-&gt;{Accept}; </code></pre> <p>gives exactly the same log output.</p> <p>According to the above linked documentation:</p> <blockquote> <p>This table is available starting from the PerlHeaderParserHandler phase</p> </blockquote> <p>So I would expect my code, running in the PerlResponseHandler phase, to be able to access the headers.</p> <p>Does anyone have any ideas what I'm doing wrong?</p> <p><strong>Edit:</strong> Using Data::Dumper hasn't really clarified matters at all.</p> <p>Code:</p> <pre><code>use Data::Dumper; $logger-&gt;warn(Dumper($r)); my $headers = $r-&gt;headers_in; $logger-&gt;warn($headers); $logger-&gt;warn(Dumper($headers)); $logger-&gt;warn('have dumped $headers'); </code></pre> <p>Output:</p> <pre><code>WARN $VAR1 = bless( do{\(my $o = '47143456365192')}, 'Apache2::RequestRec' ); WARN APR::Table=HASH(0x2ae071b06fd0) </code></pre> <p>So it seems that trying to get into $headers even through Data::Dumper results in the execution halting.</p> <p><strong>Edit:</strong> Attempting to set one of the headers fails as well.</p> <pre><code>$logger-&gt;warn('reset accept'); $r-&gt;headers_in-&gt;{'Accept'}= 'everything'; $logger-&gt;warn('post set accept'); </code></pre> <p>stops log output at the </p> <pre><code>WARN reset accept </code></pre> <p>point. I tried the <code>set(Accept =&gt; 'everything')</code> alternative as well, with the same result.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload