Skip to content

Commit 3c50188

Browse files
committed
Tests: tests for passing Date and Server headers.
1 parent b5c36b3 commit 3c50188

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

proxy_merge_headers.t

+62-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use warnings;
1010
use strict;
1111

1212
use Test::More;
13+
use Socket qw/ CRLF /;
1314

1415
BEGIN { use FindBin; chdir($FindBin::Bin); }
1516

@@ -21,7 +22,7 @@ use Test::Nginx;
2122
select STDERR; $| = 1;
2223
select STDOUT; $| = 1;
2324

24-
my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/)->plan(7)
25+
my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/)->plan(11)
2526
->write_file_expand('nginx.conf', <<'EOF');
2627
2728
%%TEST_GLOBALS%%
@@ -64,6 +65,16 @@ http {
6465
proxy_pass http://127.0.0.1:8081;
6566
proxy_set_body "body";
6667
}
68+
69+
location /passdate/ {
70+
proxy_pass http://127.0.0.1:8082;
71+
proxy_pass_header Date;
72+
proxy_pass_header Server;
73+
74+
location /passdate/no/ {
75+
proxy_pass http://127.0.0.1:8082;
76+
}
77+
}
6778
}
6879
6980
server {
@@ -80,8 +91,11 @@ http {
8091
8192
EOF
8293

94+
$t->run_daemon(\&http_daemon);
8395
$t->run();
8496

97+
$t->waitforsocket('127.0.0.1:' . port(8082));
98+
8599
###############################################################################
86100

87101
like(http_get_ims('/'), qr/ims=;blah=blah;/,
@@ -98,6 +112,11 @@ like(http_get('/nested/'), qr/X-Pad/, 'proxy_pass_header nested');
98112
unlike(http_get('/'), qr/X-Hidden/, 'proxy_hide_header inherited');
99113
unlike(http_get('/nested/'), qr/X-Hidden/, 'proxy_hide_header nested');
100114

115+
like(http_get('/passdate/'), qr/Date: passed/, 'proxy_pass_header date');
116+
like(http_get('/passdate/'), qr/Server: passed/, 'proxy_pass_header server');
117+
unlike(http_get('/passdate/no/'), qr/Date/, 'proxy_pass_header no date');
118+
unlike(http_get('/passdate/no/'), qr/Server/, 'proxy_pass_header no server');
119+
101120
###############################################################################
102121

103122
sub http_get_ims {
@@ -112,3 +131,45 @@ EOF
112131
}
113132

114133
###############################################################################
134+
135+
sub http_daemon {
136+
my $server = IO::Socket::INET->new(
137+
Proto => 'tcp',
138+
LocalHost => '127.0.0.1',
139+
LocalPort => port(8082),
140+
Listen => 5,
141+
Reuse => 1
142+
)
143+
or die "Can't create listening socket: $!\n";
144+
145+
local $SIG{PIPE} = 'IGNORE';
146+
147+
while (my $client = $server->accept()) {
148+
$client->autoflush(1);
149+
150+
my $headers = '';
151+
my $uri = '';
152+
153+
while (<$client>) {
154+
$headers .= $_;
155+
last if (/^\x0d?\x0a?$/);
156+
}
157+
158+
$uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
159+
160+
if ($uri =~ 'no') {
161+
print $client
162+
'HTTP/1.0 200 OK' . CRLF . CRLF;
163+
164+
} else {
165+
print $client
166+
'HTTP/1.0 200 OK' . CRLF .
167+
'Date: passed' . CRLF .
168+
'Server: passed' . CRLF . CRLF;
169+
}
170+
171+
close $client;
172+
}
173+
}
174+
175+
###############################################################################

0 commit comments

Comments
 (0)