comparison proxy_merge_headers.t @ 1762:5ad8f0b5fa0f

Tests: tests for passing Date and Server headers.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:27:01 +0300
parents 196d33c2bb45
children
comparison
equal deleted inserted replaced
1761:c0dfbedf52bd 1762:5ad8f0b5fa0f
8 8
9 use warnings; 9 use warnings;
10 use strict; 10 use strict;
11 11
12 use Test::More; 12 use Test::More;
13 use Socket qw/ CRLF /;
13 14
14 BEGIN { use FindBin; chdir($FindBin::Bin); } 15 BEGIN { use FindBin; chdir($FindBin::Bin); }
15 16
16 use lib 'lib'; 17 use lib 'lib';
17 use Test::Nginx; 18 use Test::Nginx;
19 ############################################################################### 20 ###############################################################################
20 21
21 select STDERR; $| = 1; 22 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 23 select STDOUT; $| = 1;
23 24
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)
25 ->write_file_expand('nginx.conf', <<'EOF'); 26 ->write_file_expand('nginx.conf', <<'EOF');
26 27
27 %%TEST_GLOBALS%% 28 %%TEST_GLOBALS%%
28 29
29 daemon off; 30 daemon off;
62 63
63 location /setbody/ { 64 location /setbody/ {
64 proxy_pass http://127.0.0.1:8081; 65 proxy_pass http://127.0.0.1:8081;
65 proxy_set_body "body"; 66 proxy_set_body "body";
66 } 67 }
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 }
67 } 78 }
68 79
69 server { 80 server {
70 listen 127.0.0.1:8081; 81 listen 127.0.0.1:8081;
71 server_name localhost; 82 server_name localhost;
78 } 89 }
79 } 90 }
80 91
81 EOF 92 EOF
82 93
94 $t->run_daemon(\&http_daemon);
83 $t->run(); 95 $t->run();
96
97 $t->waitforsocket('127.0.0.1:' . port(8082));
84 98
85 ############################################################################### 99 ###############################################################################
86 100
87 like(http_get_ims('/'), qr/ims=;blah=blah;/, 101 like(http_get_ims('/'), qr/ims=;blah=blah;/,
88 'if-modified-since cleared with cache'); 102 'if-modified-since cleared with cache');
96 unlike(http_get('/'), qr/X-Pad/, 'proxy_pass_header default'); 110 unlike(http_get('/'), qr/X-Pad/, 'proxy_pass_header default');
97 like(http_get('/nested/'), qr/X-Pad/, 'proxy_pass_header nested'); 111 like(http_get('/nested/'), qr/X-Pad/, 'proxy_pass_header nested');
98 unlike(http_get('/'), qr/X-Hidden/, 'proxy_hide_header inherited'); 112 unlike(http_get('/'), qr/X-Hidden/, 'proxy_hide_header inherited');
99 unlike(http_get('/nested/'), qr/X-Hidden/, 'proxy_hide_header nested'); 113 unlike(http_get('/nested/'), qr/X-Hidden/, 'proxy_hide_header nested');
100 114
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
101 ############################################################################### 120 ###############################################################################
102 121
103 sub http_get_ims { 122 sub http_get_ims {
104 my ($url) = @_; 123 my ($url) = @_;
105 return http(<<EOF); 124 return http(<<EOF);
110 129
111 EOF 130 EOF
112 } 131 }
113 132
114 ############################################################################### 133 ###############################################################################
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 ###############################################################################