Mercurial > hg > nginx-tests
comparison fastcgi_merge_params.t @ 182:23f81eb0a817
Tests: proxy_set_header/fastcgi_param/scgi_param tests.
These tests cover several problems, in particular ticket #45
(http://trac.nginx.org/nginx/ticket/45).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 08 Nov 2011 21:03:06 +0300 |
parents | |
children | 101b092b67e2 |
comparison
equal
deleted
inserted
replaced
181:e4024348b5ed | 182:23f81eb0a817 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for fastcgi_param inheritance. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 eval { require FCGI; }; | |
25 plan(skip_all => 'FCGI not installed') if $@; | |
26 | |
27 | |
28 my $t = Test::Nginx->new()->has(qw/http fastcgi cache/)->plan(9) | |
29 ->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 fastcgi_cache_path %%TESTDIR%%/cache levels=1:2 | |
42 keys_zone=NAME:10m; | |
43 | |
44 fastcgi_param HTTP_X_BLAH "blah"; | |
45 | |
46 server { | |
47 listen 127.0.0.1:8080; | |
48 server_name localhost; | |
49 | |
50 fastcgi_cache NAME; | |
51 | |
52 location / { | |
53 fastcgi_pass 127.0.0.1:8081; | |
54 } | |
55 | |
56 location /no/ { | |
57 fastcgi_pass 127.0.0.1:8081; | |
58 fastcgi_cache off; | |
59 } | |
60 | |
61 location /custom/ { | |
62 fastcgi_pass 127.0.0.1:8081; | |
63 fastcgi_param HTTP_X_BLAH "custom"; | |
64 } | |
65 } | |
66 } | |
67 | |
68 EOF | |
69 | |
70 $t->run_daemon(\&fastcgi_daemon); | |
71 $t->run(); | |
72 | |
73 ############################################################################### | |
74 | |
75 like(http_get_ims('/'), qr/ims=;/, | |
76 'if-modified-since cleared with cache'); | |
77 | |
78 TODO: { | |
79 local $TODO = 'not yet'; | |
80 | |
81 like(http_get_ims('/'), qr/iums=;/, | |
82 'if-unmodified-since cleared with cache'); | |
83 | |
84 } | |
85 | |
86 like(http_get_ims('/'), qr/blah=blah;/, | |
87 'custom params with cache'); | |
88 | |
89 TODO: { | |
90 local $TODO = 'not yet'; | |
91 | |
92 like(http_get_ims('/no/'), qr/ims=blah;/, | |
93 'if-modified-since preserved without cache'); | |
94 | |
95 } | |
96 | |
97 like(http_get_ims('/no/'), qr/iums=blah;/, | |
98 'if-unmodified-since preserved without cache'); | |
99 like(http_get_ims('/'), qr/blah=blah;/, | |
100 'custom params without cache'); | |
101 | |
102 like(http_get_ims('/custom/'), qr/ims=;/, | |
103 'if-modified-since cleared with cache custom'); | |
104 | |
105 TODO: { | |
106 local $TODO = 'not yet'; | |
107 | |
108 like(http_get_ims('/custom/'), qr/iums=;/, | |
109 'if-unmodified-since cleared with cache custom'); | |
110 } | |
111 | |
112 like(http_get_ims('/custom/'), qr/blah=custom;/, | |
113 'custom params with cache custom'); | |
114 | |
115 ############################################################################### | |
116 | |
117 sub http_get_ims { | |
118 my ($url) = @_; | |
119 return http(<<EOF); | |
120 GET $url HTTP/1.0 | |
121 Host: localhost | |
122 Connection: close | |
123 If-Modified-Since: blah | |
124 If-Unmodified-Since: blah | |
125 | |
126 EOF | |
127 } | |
128 | |
129 ############################################################################### | |
130 | |
131 sub fastcgi_daemon { | |
132 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); | |
133 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, | |
134 $socket); | |
135 | |
136 my $count; | |
137 while( $request->Accept() >= 0 ) { | |
138 $count++; | |
139 | |
140 my $ims = $ENV{HTTP_IF_MODIFIED_SINCE}; | |
141 my $iums = $ENV{HTTP_IF_UNMODIFIED_SINCE}; | |
142 my $blah = $ENV{HTTP_X_BLAH}; | |
143 | |
144 print <<EOF; | |
145 Location: http://127.0.0.1:8080/redirect | |
146 Content-Type: text/html | |
147 | |
148 ims=$ims;iums=$iums;blah=$blah; | |
149 EOF | |
150 } | |
151 | |
152 FCGI::CloseSocket($socket); | |
153 } | |
154 | |
155 ############################################################################### |