Reputation: 12311
I am using HTTP::Daemon
for a HTTP-server.
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);
}
I try to overwrite the HTTP-header entry for Server. But, all I get is a 2nd entry with my value "MyServer".
Any idea how to overwrite the original value "libwww-perl-daemon"?
There is a method product_tokens
for getting the value, but it is not able to set the value.
Upvotes: 4
Views: 202
Reputation: 132758
The docs say you should make a subclass:
=item $d->product_tokens
Returns the name that this server will use to identify itself. This is the string that is sent with the C response header. The main reason to have this method is that subclasses can override it if they want to use another product name.
The default is the string "libwww-perl-daemon/#.##" where "#.##" is replaced with the version number of this module.
So, you write a small subclass and then use your subclass to make the 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( ... );
Upvotes: 4