[英]HTTP::Daemon: How to set a custom value for Server in HTTP-Header?
我正在使用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
用于获取值,但它无法设置值。
文档说你应该创建一个子类:
=item $d->product_tokens
返回此服务器用于标识自身的名称。 这是与 C 响应 header 一起发送的字符串。 拥有此方法的主要原因是子类如果想使用另一个产品名称可以覆盖它。
默认值为字符串“libwww-perl-daemon/#.##”,其中“#.##”替换为该模块的版本号。
因此,您编写了一个小子类,然后使用您的子类制作 object:
use v5.12;
package Local::HTTP::Daemon {
use parent qw(HTTP::Daemon);
sub product_tokens {
... # whatever you want
}
}
my $d = Local::HTTP::Daemon->new( ... );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.