【发布时间】:2021-04-22 23:55:17
【问题描述】:
我正在使用 HTTP::Daemon 作为 HTTP 服务器。
use strict;
use warnings;
use HTTP::Daemon;
my $d = HTTP::Daemon->new (Listen => 1, LocalPort => 8080, ReuseAddr => 1, Blocking => 0) or die "error daemon: " . $!;
while (1)
{
my $c = $d->accept ();
if (defined ($c))
{
my $req = $c->get_request ();
my $res = HTTP::Response->new (200);
$res->header ("Server" => "MyServer"); # try to overwrite the internel builtin value
$res->content ("OK");
$c->send_response ($res);
$c->autoflush ();
undef ($c);
}
sleep (1);
}
我尝试覆盖服务器的 HTTP 标头条目。 但是,我得到的只是第二个条目,其值为“MyServer”。
知道如何覆盖原始值“libwww-perl-daemon”吗?
有一个方法product_tokens获取值,但是不能设置值。
【问题讨论】:
-
“有一个方法product_tokens获取值,但是不能设置值。” - asdocumented“主要原因有这个方法是子类可以覆盖如果他们想使用另一个产品名称。”。因此,如果你想要一个不同的值,子类 HTTP::Daemon 并覆盖这个方法。
标签: perl http http-daemon