简体   繁体   English

mod_perl headers_in不起作用

[英]mod_perl headers_in not working

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. 我在Red Hat 5.2上使用mod_perl 2和Apache 2.2.3,我正在尝试访问请求头,但是Apache2 :: RequestRec headers_in方法(或者更确切地说,它的返回值)表现不像我想的那样期望。

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');
$logger->warn($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. 一旦尝试访问APR :: Table,执行就会暂停。 The tied interface for APR::Table had the same effect - ie changing the get('Accept') line to: APR :: Table的绑定接口具有相同的效果 - 即将get('Accept')行更改为:

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 此表从PerlHeaderParserHandler阶段开始提供

So I would expect my code, running in the PerlResponseHandler phase, to be able to access the headers. 所以我希望我的代码在PerlResponseHandler阶段运行,能够访问头文件。

Does anyone have any ideas what I'm doing wrong? 有没有人有任何想法我做错了什么?

Edit: Using Data::Dumper hasn't really clarified matters at all. 编辑:使用Data :: Dumper根本没有明确澄清问题。

Code: 码:

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

Output: 输出:

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. 因此,即使通过Data :: Dumper尝试进入$ header也会导致执行暂停。

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. 我也尝试了set(Accept => 'everything')替代方案,结果相同。

Is there anything in the apache logs? apache日志中有什么内容吗? It seems if your code stops executing there should be an error somewhere saying why. 看来如果你的代码停止执行,那么应该有一个错误说明原因。

Have you tried getting the Accept header without assigning the header object to $header: 您是否尝试获取Accept标头而未将标头对象分配给$ header:

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

This works in my code running in the PerlResponseHandler phase. 这适用于我在PerlResponseHandler阶段运行的代码。

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. 有点奇怪,它很高兴能够创建一个APR :: Table对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM