我进行了以下修改:
my $response = $ua->get( 'http://www.eurogamer.net/articles/df-hardware-wii-u-graphics-power-finally-revealed' );
say $response->headers->as_string;
看到了这个:
Cache-Control: max-age=60s
Connection: close
Date: Wed, 06 Feb 2013 23:51:15 GMT
Via: 1.1 varnish
Age: 0
Server: Apache
Vary: Accept-Encoding
Content-Length: 50519
Content-Type: text/html; charset=ISO-8859-1
Client-Aborted: die
Client-Date: Wed, 06 Feb 2013 23:50:50 GMT
Client-Peer: 94.198.83.18:80
Client-Response-Num: 1
X-Died: Illegal field name 'X-Meta-Twitter:card' at .../HTML/HeadParser.pm line 207.
X-Varnish: 630361704
它似乎不喜欢第<meta name="twitter:card" content="summary" />
27 行的标签。它说它死了。
它似乎将任何meta
具有name
属性的标签转换为"X-Meta-\u$attr->{name}"
“标题”。然后它尝试将content
属性的值存储为 X-meta“标题”值。像这样(从第 194 行开始):
if ($tag eq 'meta') {
my $key = $attr->{'http-equiv'};
if (!defined($key) || !length($key)) {
if ($attr->{name}) {
$key = "X-Meta-\u$attr->{name}"; # <-- Here's the little trick
} elsif ($attr->{charset}) { # HTML 5 <meta charset="...">
$key = "X-Meta-Charset";
$self->{header}->push_header($key => $attr->{charset});
return;
} else {
return;
}
}
$self->{'header'}->push_header($key => $attr->{content});
}
我将此模块的修改副本推送到 PERL5LIB 目录中。我将步骤包装push_header
在一个eval
块中并完全下载了页面。