@@ -10,6 +10,7 @@ use warnings;
10
10
use strict;
11
11
12
12
use Test::More;
13
+ use Socket qw/ CRLF / ;
13
14
14
15
BEGIN { use FindBin; chdir ($FindBin::Bin ); }
15
16
@@ -21,7 +22,7 @@ use Test::Nginx;
21
22
select STDERR ; $| = 1;
22
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
26
-> write_file_expand(' nginx.conf' , <<'EOF' );
26
27
27
28
%%TEST_GLOBALS%%
@@ -64,6 +65,16 @@ http {
64
65
proxy_pass http://127.0.0.1:8081;
65
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
80
server {
@@ -80,8 +91,11 @@ http {
80
91
81
92
EOF
82
93
94
+ $t -> run_daemon(\&http_daemon);
83
95
$t -> run();
84
96
97
+ $t -> waitforsocket(' 127.0.0.1:' . port(8082));
98
+
85
99
# ##############################################################################
86
100
87
101
like(http_get_ims(' /' ), qr / ims=;blah=blah;/ ,
@@ -98,6 +112,11 @@ like(http_get('/nested/'), qr/X-Pad/, 'proxy_pass_header nested');
98
112
unlike(http_get(' /' ), qr / X-Hidden/ , ' proxy_hide_header inherited' );
99
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
122
sub http_get_ims {
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
+ # ##############################################################################
0 commit comments