Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/server tokens #5

Merged
merged 2 commits into from Aug 17, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/service-parameters.txt
Expand Up @@ -91,6 +91,11 @@ For all services:
| | | |where trusted means their | | | | |where trusted means their |
| | | |X-Forwarded-For/etc headers| | | | |X-Forwarded-For/etc headers|
| | | |are not munged. | | | | |are not munged. |
|---------------------------+----+---------------------+---------------------------|
| | | |Whether to provide a |
|server_tokens |bool|true |'Server' header in the |
| | | |headers that are sent back |
| | | |to the user |
+----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+


Only for 'reverse_proxy' services: Only for 'reverse_proxy' services:
Expand Down
8 changes: 4 additions & 4 deletions lib/Perlbal/ClientHTTPBase.pm
Expand Up @@ -541,7 +541,7 @@ sub _serve_request {


# now set whether this is keep-alive or not # now set whether this is keep-alive or not
$res->header("Date", HTTP::Date::time2str()); $res->header("Date", HTTP::Date::time2str());
$res->header("Server", "Perlbal"); $res->header("Server", "Perlbal") if $self->{service}{server_tokens};
$res->header("Last-Modified", $lastmod); $res->header("Last-Modified", $lastmod);


if (-f _) { if (-f _) {
Expand Down Expand Up @@ -708,7 +708,7 @@ sub _serve_request_multiple_poststat {
} }


$res->header("Date", HTTP::Date::time2str()); $res->header("Date", HTTP::Date::time2str());
$res->header("Server", "Perlbal"); $res->header("Server", "Perlbal") if $self->{service}{server_tokens};
$res->header("Last-Modified", $lastmod); $res->header("Last-Modified", $lastmod);
$res->header("Content-Type", $mime); $res->header("Content-Type", $mime);
# has to happen after content-length is set to work: # has to happen after content-length is set to work:
Expand Down Expand Up @@ -852,7 +852,7 @@ sub _simple_response {
$res->header('Content-Length', length($body)); $res->header('Content-Length', length($body));
} }


$res->header('Server', 'Perlbal'); $res->header('Server', 'Perlbal') if $self->{service}{server_tokens};


$self->setup_keepalive($res); $self->setup_keepalive($res);


Expand Down Expand Up @@ -899,7 +899,7 @@ sub send_full_response {
$res->header('Content-Length', length($$bref)); $res->header('Content-Length', length($$bref));
} }


$res->header('Server', 'Perlbal'); # Tunable? $res->header('Server', 'Perlbal') if $self->{service}{server_tokens};
# $res->header('Date', # We should do this # $res->header('Date', # We should do this


$self->setup_keepalive($res, $options->{persist_client}); $self->setup_keepalive($res, $options->{persist_client});
Expand Down
5 changes: 5 additions & 0 deletions lib/Perlbal/Manual/Internals.pod
Expand Up @@ -1009,6 +1009,11 @@ Comma-separated seconds (full or partial) to delay between retries.
Milliseconds of latency to add to request. Milliseconds of latency to add to request.




=item server_tokens

Boolean; whether to provide a "Server" header.


=item _stat_requests =item _stat_requests


Total requests to this service. Total requests to this service.
Expand Down
8 changes: 8 additions & 0 deletions lib/Perlbal/Manual/ReverseProxy.pod
Expand Up @@ -310,6 +310,14 @@ What path the OPTIONS request sent by C<verify_backend> should use.


Default is C<*>. Default is C<*>.


=item B<server_tokens> = bool

Whether to provide a "Server" header.

Perlbal by default adds a header to all replies (such as the web_server role). By setting this default to "off", you can prevent Perlbal from identifying itself.

Default is C<on>.

=back =back




Expand Down
8 changes: 8 additions & 0 deletions lib/Perlbal/Manual/WebServer.pod
Expand Up @@ -107,6 +107,14 @@ If PUT requests are enabled, require this many levels of directories to already


Default is 0. Default is 0.


=item B<server_tokens> = bool

Whether to provide a "Server" header.

Perlbal by default adds a header to all replies (such as the web_server role). By setting this default to "off", you can prevent Perlbal from identifying itself.

Default is C<on>.



=back =back


Expand Down
7 changes: 7 additions & 0 deletions lib/Perlbal/Service.pm
Expand Up @@ -101,6 +101,7 @@ use fields (
'enable_error_retries', # bool: whether we should retry requests after errors 'enable_error_retries', # bool: whether we should retry requests after errors
'error_retry_schedule', # string of comma-separated seconds (full or partial) to delay between retries 'error_retry_schedule', # string of comma-separated seconds (full or partial) to delay between retries
'latency', # int: milliseconds of latency to add to request 'latency', # int: milliseconds of latency to add to request
'server_tokens', # bool: whether to provide a "Server" header


# stats: # stats:
'_stat_requests', # total requests to this service '_stat_requests', # total requests to this service
Expand Down Expand Up @@ -611,6 +612,12 @@ our $tunables = {
check_role => '*', check_role => '*',
}, },


'server_tokens' => {
des => 'Whether to provide a "Server" header.',
check_role => '*',
check_type => 'bool',
default => 1,
},


}; };
sub autodoc_get_tunables { return $tunables; } sub autodoc_get_tunables { return $tunables; }
Expand Down
56 changes: 56 additions & 0 deletions t/13-server-tokens.t
@@ -0,0 +1,56 @@
#!/usr/bin/perl

use strict;
use Perlbal::Test;

use Test::More tests => 13;
require HTTP::Request;

# Build conf files
my $dir = tempdir();
my @confs = (
[ new_port() => sub { my $port = shift; qq{
CREATE SERVICE test
SET role = web_server
SET listen = 127.0.0.1:$port
SET docroot = $dir
SET server_tokens = on
ENABLE test
} } ],

[ new_port() => sub { my $port = shift; qq{
CREATE SERVICE test
SET role = web_server
SET listen = 127.0.0.1:$port
SET docroot = $dir
SET server_tokens = off
ENABLE test
} } ],
);

my $count = 0;
foreach my $pair (@confs) {
my $port = $pair->[0];
my $conf = $pair->[1]->($port);
my $msock = start_server($conf);
ok($msock, "manage sock");
my $ua = ua();
ok($ua, "ua");

my $req = HTTP::Request->new( GET => "http://127.0.0.1:$port/" );
my $res = $ua->request($req);

ok( $res, 'Got result' );
isa_ok( $res, 'HTTP::Response' );
ok( $res->is_success, 'Result is successful' );

if ( $count++ == 0 ) {
# check it's on
ok( $res->header('Server'), 'Server header exists' );
is( $res->header('Server'), 'Perlbal' );
} else {
# check it's off
ok( ! $res->header('Server'), 'Server header missing' );
}
}